English 中文(简体)
MVC框架中的静态页面?
原标题:Static pages in MVC framework?

你们在MVC框架中放置静态页面(如“主页”)的位置在哪里?你们有“主页控制器”吗?有“页面控制器”吗?你们为每个静态页面创建操作吗?

我现在正在使用CFWheels,我试图找出最佳放置它们的位置。


编辑:显然,CFWheels不需要你为所有视图创建动作。因此,您只需创建一个空控制器,并像调用动作一样调用视图,但不必编写空函数。

最佳回答

在一天结束时,静态页面是一个没有模型的视图,这是基于用户通过命中特定路由从您的服务器请求的操作返回的。 :-)

是的,从技术上讲,您可以向用户公开视图资源的直接位置,并依赖于http守护程序去获取并返回它。但是,这意味着资源URL现在不再与您想要公开的资源的语义相关,而与实际位相关。这意味着如果您需要该资源的另一种表示形式,则必须在不同的URL上公开它。

因此,在创建您的 Web 应用程序的结构时,首先考虑要公开的 URL 和资源,然后考虑如何实现每个资源。

问题回答

CakePHP(我猜,Ruby On Rails也是)有一个“页面”控制器。有一个路由功能,它将请求重定向到/pages/foo/pages/display/foo。同样,/被重定向到/pages/display/homedisplay动作查找具有匹配名称的任何文件的views/pages文件夹,并呈现该文件。

我使用简单的CMS和私人管理员页面将我的静态页面放入数据库中。

这样,客户可以自己进行简单的修改。

在Wheels中,您甚至不需要创建控制器文件。

If you create your view here: views/about/index.cfm

You don t need to create the controller file at all. Then you should be able to just call this with no problems: http://www.example.com/about





相关问题
Choosing the right subclass to instantiate programmatically

Ok, the context is some serialization / deserialization code that will parse a byte stream into an object representation that s easier to work with (and vice-versa). Here s a simplified example ...

Design pattern for managing queues and stacks?

Is there a design pattern for managing a queue or a stack? For example, we are looking to manage a list of tasks. These tasks will be added to a group queue, users will then be able to pull off the ...

Organizing classes using the repository design pattern

I have started upgrading one of our internal software applications, written in ASP.NET Web Forms, and moving to ASP.NET MVC. I am trying to leverage the Repository design pattern for my classes, ...

Misuse of Observer Pattern?

I have a Car object which contains a latitude field and a longitude field. I use the observer pattern so that any time either of these fields change in my application, my car object is notified. I ...

How are Models (in MVC) and DAOs supposed to interact?

How are models and DAOs supposed to interact? I m in the process of putting together a simple login module and I m unsure where to put the "business logic." If I put the logic with the data in the ...

热门标签