0
votes

I'm using CakePHP to build a blog (just a personal project, nothing serious) and for the moment I have the next controllers:

  • PostsControllers (actions: index, about, archive, show, edit)
  • UsersControllers (actions: register, login, logout)

I think that actions like 'index', 'about' and 'archive' should be placed in a different controller (like BlogsController) because they are not actions related to a single post.

I have been searching in the Internet and all I have found is that most people use only a single controller for both blog and post actions (a BlogsController or a PostsController).

So my question: should I have a separated controller for actions like 'index', 'about', 'archive' and so on?

1

1 Answers

3
votes

No, you should keep a controller for each discrete entity type (eg, Post, User, Comment). You can then have actions such as /posts/view/5 to view a blog post of ID 5. If you want to make the URL reflect the blog-ness, then you can map a route for /blog/5 or /blog/posts/5 (see the CakePHP documentation on routing).

If you plan on creating a site with more than just a blog, you could also consider creating a blog plugin with CakePHP (again, see the documentation). Then all your blog-related actions will be confined within a single plugin for organization. Consequently, this also makes it easier to deploy your blogging code for other websites.