• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check method/function exist with Controller

#1
Hi guys,

can anyone please help, how can i check if method/funcion exist within class/controller? say:

PHP Code:
class User extends CI_Controller {
 
   public function __construct() {
 
     parent::__construct();
 
   }

 
   public function login() {
 
      ...
 
   }

the idea is, i want to check function "login()" if exist and execute.

hope someone could help.

Thanks in advanced 
Reply

#2
Depending where in the application you want this to happen, you can use the _remap function from CI
https://ellislab.com/codeigniter/user-gu...llers.html


PHP Code:
public function _remap($method$params = array())
{
    
$method 'process_'.$method;
    if (
method_exists($this$method))
    {
        return 
call_user_func_array(array($this$method), $params);
    }
    
show_404();

Reply

#3
What is your idea ?
Where you want to make this check?
Best VPS Hosting : Digital Ocean
Reply

#4
You can use the _remap method from CI as described here:

http://www.codeigniter.com/userguide3/ge...thod-calls

The following short example shows you a quick usage

PHP Code:
class User extends CI_Controller {
    public function 
__construct() {
      
parent::__construct();
    }

    function 
_remap($method)
    {
        if(
method_exists($this,$method))
        {
            
call_user_func(array($this$method));
            return 
false;
        }
        else
        {
            echo 
'Method not found!';
        }
    }

    
// .... your methods ....



Reply

#5
Ahh, thank you guys. very much appreciated all your help.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.