dongzhuoxie1244 2012-03-19 05:47
浏览 10
已采纳

视图中的业务逻辑 - CakePHP

I have a home page which is a blog by default. I want the user to be able to turn the blog off in case they want a static page instead [set in the database]

Problem is:

1) Do I do the business in the view (Which I know is bad practice)

or

2) Do I do it all in the controller (Which will require me to pull the boolean value from the database)

Thanks!

  • 写回答

3条回答 默认 最新

  • douluo3256 2012-03-20 20:14
    关注

    It is always better to keep the business logic in the Controller. Breaking a paradigm for the sake of making it more simple is not a good idea.

    Here is how I would do it.

    Since the view for the Blog Page vs Static Page is virtually the same (with the exception of comments), I would say make them both exactly the same. Then set a flag in the database and for the page you are adding to identify if the page is static.

    In the view, put a simple if (static) don't show comments statement that will not show the comments. Then there is no changing of logic and no logic required in the controller.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?