CodeIgniter Forums
Protecting certain functions in controller form being used by user directly - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Protecting certain functions in controller form being used by user directly (/showthread.php?tid=50615)



Protecting certain functions in controller form being used by user directly - El Forum - 04-01-2012

[eluser]bleu[/eluser]
The are certain functions in my controllers that I do not want people to have access to.

I may want only one main function to be accessed in that controller through the browser.

The other functions should be accessed by that main function in that controller only

How can I achieve that

Example: controller/function1 should be able to be accessed by the browser other functions should be accessed by function1(i.e. function2,function3 should be accessed by function1)


Protecting certain functions in controller form being used by user directly - El Forum - 04-02-2012

[eluser]soupli[/eluser]
You could use the controllers _remap() function:
http://ellislab.com/codeigniter/user-guide/general/controllers.html#remapping

or choose to use URI Routing:
http://ellislab.com/codeigniter/user-guide/general/routing.html


Protecting certain functions in controller form being used by user directly - El Forum - 04-02-2012

[eluser]PhilTem[/eluser]
You could also use what is mentioned in the user's guide about private functions.


Protecting certain functions in controller form being used by user directly - El Forum - 04-02-2012

[eluser]InsiteFX[/eluser]
Code:
function _name()  // CI private

private function name()

protected function name()



Protecting certain functions in controller form being used by user directly - El Forum - 04-02-2012

[eluser]bleu[/eluser]
[quote author="InsiteFX" date="1333366144"]
Code:
function _name()  // CI private

private function name()

protected function name()
[/quote]

what is difference between ci private and php private?


Protecting certain functions in controller form being used by user directly - El Forum - 04-02-2012

[eluser]PhilTem[/eluser]
PHP private is private in terms of object visibility. CI private is only in terms of URI. Any method defined public but starting with an underscore won't be accessible by any user
Code:
public function _not_publicly_accessible()
since this is what CI's designed to see as private.

If you defined any method with visibility private/protected, it won't however be accessible by the CI super-object, too. But that's because it can't call
Code:
$controller->protected_method()
which is due to the visibility restrictions PHP provides.


Protecting certain functions in controller form being used by user directly - El Forum - 04-02-2012

[eluser]bleu[/eluser]
[quote author="PhilTem" date="1333373638"]PHP private is private in terms of object visibility. CI private is only in terms of URI. Any method defined public but starting with an underscore won't be accessible by any user
Code:
public function _not_publicly_accessible()
since this is what CI's designed to see as private.

If you defined any method with visibility private/protected, it won't however be accessible by the CI super-object, too. But that's because it can't call
Code:
$controller->protected_method()
which is due to the visibility restrictions PHP provides.[/quote]

Thanks