CodeIgniter Forums
Controllers: private functions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Controllers: private functions (/thread-57176.html)



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

[eluser]Unknown[/eluser]
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:

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

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

Code:
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

[eluser]InsiteFX[/eluser]
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

[eluser]Aken[/eluser]
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.