Welcome Guest, Not a member yet? Register   Sign In
Detect Function In Controller
#1

[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
#2

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

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

$this->uri->segments;

?
#4

[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();
#5

[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.
#6

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB