Monday, July 16, 2012

Codeigniter php frameworks: controllers part 6

Codeigniter php frameworks is back, now we going to learn controllers part 6, about private function and organizing your controllers into sub-folders. If you not have read the previous part, please read it before read this post. Okay about private function, in some cases you may want certain functions hidden from public access. To make a function private, simply add an underscore as the name prefix and it will not be served via a URL request. For example, if you were to have a function like this.

private function _utility()
{
  // some code
}

Trying to access it via the URL, like this example.com/index.php/blog/_utility/ will not work. Now Codeigniter php frameworks talk about organizing your controllers into sub-folders, if you are building a large application you might find it convenient to organize your controllers into sub-folders. Codeigniter permits you to do this. Simply create folders within your application/controllers directory and place your controller classes within them. For the note, when using this feature the first segment of your URI must specify the folder. For example, let’s say you have a controller located here application/controllers/products/shoes.php.

To call the above controllers your URI will look something like this example.com/index.php/products/shoes/show/123. Each of your sub-folders may contain a default controller which will be called if the URL contains only the sub-folder. Simply name your default controller as specified in your application/config/routes.php file. I think just all for this part, see you in last part of controllers at Codeigniter php frameworks.

This post of Codeigniter php frameworks: controllers part 6 is references from http://codeigniter.com/user_guide/general/controllers.html.

No comments:

Post a Comment