CodeIgniter Forums
Controllers: private functions - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived General Discussion (
+--- Thread: Controllers: private functions (/thread-57176.html)

Controllers: private functions - El Forum - 02-22-2013

My question is about private functions used in controllers.

The User Guide states that adding underscore before the name of that function makes the function private, and it won't be accessible via URI:

private function _somefunction ($first_parameter, $second_parameter) { etc.

And yet, on the same page of the User Guide ("Controllers") there's this example:

public function _remap ($method) {

Why is the function marked with underscore is declared as public - am I missing something? Is declaring function as public overrules the underscore in its name, or is there any other reason for that? Or perhaps, it's an error in the User Guide?

Thank you!

Controllers: private functions - El Forum - 02-22-2013

The underscore used in that example is an internal CI ( underscore ).

The _remap method is declared with the underscore.

Controllers: private functions - El Forum - 02-22-2013

CI will treat an opening underscore as a "private" no matter what scope the method is defined under. Or, you can still define a method as private and name it whatever you want and it won't be accessible.

_remap() is a special method used by CI. There's info about it in the user guide.