Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望任何/api以 JSON 格式开头的 URL 的响应。有没有办法为我的整个应用程序配置这个?我正在使用 Symfony2 2.0 版。
/api
如果您对路由使用注释并在 中激活控制器routing.yml,您可以这样做:
routing.yml
Api: resource: "@ApiBundle/Controller" type: annotation defaults: { _format: 'json' }
如果您只想为一个控制器设置它,请在控制器级别注释上设置它:
/** * @Route("/api", defaults={"_format": "json"}) */ class ApiController { }
我是位运算的初学者(在 C 方面也不是很有经验),我遇到了以下表达式:
x |= (1<<y)
起初我以为它的意思是“x 等于 x 或 y 左移一位”,但后来我意识到这将是:
x |= (y<<1)