Controller file vs controller function

I have been fallowing the "Codeigniter from scratch" screencasts at and I have the fallowing doubt about when or how you choose between creating a new controller function using the site controller file and creating a new controller file with new functions. it seams that you can fit all your controllers functions in a single file.

I'll appreciate the any explanation.



[eluser]Ben Edmunds[/eluser]
Hey Carlos,

Theoretically you could build an entire site with one controller but the code would quickly become unmanageable and just bad.

First off some semantics, the controller files are usually called controllers and the controller's functions are usually called methods or actions.

So what you want to do is separate you site logically into controllers. For example, if you have a site with a home page, blog, and article page you would probably want three controllers; welcome, blog, articles and then you would have methods inside those preforming the actions for that part of the site.

As an example your blog controller might look like this:
class Blog extends Controller {
   function index() {
      //display the blog posts

   function view($id) {
      //display the blog post by id

   function post() {
      //new blog post

Make sense?

Thanks Ben!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.