CodeIgniter Forums
Detect Function In Controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Detect Function In Controller (/showthread.php?tid=8915)



Detect Function In Controller - El Forum - 06-05-2008

[eluser]gedev2006[/eluser]
Hi

I have a class for example with a constructor. The construct function detects if a user is logged in or not before allowing access to any functions.

What I want is to be able for the constructor to detect which function the user is trying to access to allow specific functions to be used regardless of the logged in state. This can be done in each function that needs a login, but there are allot of functions and would rather have 1 check only

Thanks


Detect Function In Controller - El Forum - 06-05-2008

[eluser]wiredesignz[/eluser]
uri->segments will show you the path the user has chosen.


Detect Function In Controller - El Forum - 06-05-2008

[eluser]gedev2006[/eluser]
do you mean:

$this->uri->segments;

?


Detect Function In Controller - El Forum - 06-05-2008

[eluser]Pascal Kriete[/eluser]
That is what he meant, another way to do it is to use the router:
Code:
$RTR =& load_class('Router');
$method = $RTR->fetch_method();



Detect Function In Controller - El Forum - 06-05-2008

[eluser]louis w[/eluser]
You could pass the name of the function to the checker like this:

$this->checkPermissions(__FUNCTION__);

Also, if you want the classname+function use:

$this->checkPermissions(__METHOD__);

The only thing is you would have to have this call inside each one of your methods.


Detect Function In Controller - El Forum - 06-05-2008

[eluser]xwero[/eluser]
FYI __METHOD__ is not available in php4


Detect Function In Controller - El Forum - 06-05-2008

[eluser]louis w[/eluser]
Good point, you could use __CLASS__.':'.__FUNCTION__ if you are over 4.3

Personally I do not support php 4 or keep it in mind when giving assistance. It is long dead to me.