Reputation: 1944
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!
Upvotes: 0
Views: 185
Reputation: 11574
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.
Upvotes: 1
Reputation: 399
If it is a simple blog and you think it will not scale up later, then it is fine to put the logic in the views. MVC is only a paradigm. It need not be followed religiously. You are free to break the pattern as you think it fits.
Upvotes: -1
Reputation: 34155
Don't put any kind of login in your views, except simple presentation logic. Instead I would suggest you to add a check in your Controller or better Model(Since, it deals with database.)
Upvotes: 2