使用 Symfony MVC 的静态网页
我是 symfony 的新手。
我需要构建一个静态网页。该页面仅包含一个表单,但它可以是任何其他内容:但是内容是静态的。
symfony 文档描述了这种用户请求处理模式:
user http request -> symfony 路由器匹配正确的路由(控制器+操作)->执行控制器上的操作 ->该操作生成http响应
这当然是处理需要从数据库等获取数据的请求的有效模式(非静态内容)
对于静态内容,控制器上的操作将始终生成相同的http响应。
那么对于静态内容,symfony中有没有一种方法可以不通过控制器来访问静态页面呢?
我知道我可以在文档根文件夹树下放置一个静态 html,但这似乎不是 symfony 最佳实践,不是吗?
太感谢了
I'am new to symfony.
I need to build a static web page. The page simply contains a form but it could be any othe content: however the content is static.
The symfony documentation describes this pattern for user request handling:
user http request -> symfony router match the correct route (controller + action) -> an action on the controller is executed -> the action generate the http response
This is of course a valid pattern for handling requests that need to take data from database etc (non-static content)
For static content the action on the controller will always generate the same http response.
So for static content is there a way in symfony to access the static page without passing through the controller?
I know I can place a static html under the document root folder tree, but this seems not to be a symfony best-practice, does it??
Thank you so much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你说的是1.4 Symfony,你可以使用这个方法对于静态页面。或者你可以
If you said about 1.4 Symfony, you can use this method for static page. Or you can
创建一个静态包,如 Liip 博客文章中所示,并将静态内容保留在那里。我不认为当请求到达控制器时它应该与 Model 交互。
控制器只是起点。模型也不需要与数据库连接。这可能是一些逻辑。如果您阅读了 5 分钟的快速入门,那就太好了。
http://symfony.com/doc/2.0/book/page_creation.html
http://blog.liip.ch/archive/2011/05/19/symfony2-bundle-struct-a-use-case.html
Create a static bundle as in Liip blog post and keep your static contents there. I don't think when a request comes to a controller it should interact with Model .
Controller is just the starting point. Models doesn't need to be be connections with Database also. It can be some logic. Good if you read the quick start of 5 minutes.
http://symfony.com/doc/2.0/book/page_creation.html
http://blog.liip.ch/archive/2011/05/19/symfony2-bundle-structure-a-use-case.html
您可以使用 FrameworkBundle:Template:template 控制器来执行此操作,如文档
You can do this with the FrameworkBundle:Template:template controller as explained in the documentation