开发者

ReflectionClass in Codeigniter Model

I need to verify the existence of a method in a controller from a model with codeigniter 2.0.2. and HMVC.

I'm trying to do with ReflectionClass:hasMethod(), without success.

My code in Model:

function hasPanel($controller){
    $rc = new ReflectionClass($controller);
    if($rc::hasMethod("panel_base")){
        return true;
    }
    return false;
}

And the unwelcome error:

Fatal error:  Uncaught exception 'ReflectionException' with message 'Class administracion does not exist' in D:\xampp\htdocs\sea\application\models\auth\permisos.php:368
Stack trace:
#0 D:\xampp\htdocs\sea\application\models\auth\permisos.php(368): ReflectionClass->__construct('administracion')
#1 D:\xampp\htdocs\sea\application\models\auth\permisos.php(357): Permisos->hasPanel('administracion')
#2 D:\xampp\htdocs\sea\application\controllers\auth\identificar.php(101): Permisos->getControladores('administracion')
#3 [internal function]: Identificar->modulo()
#4 D:\xampp\htdocs\sea\application\core\Admin_controller.php(317): call_user_func_array(Array, Array)
#5 D:\xampp\htdocs\sea\system\core\CodeIgniter.php(305): Admin_controller->_remap('modulo', Array)
#6 D:\xampp\htdocs\sea\www\index.php(252): require_once('D:\xampp\htdocs...')
#7 {main}
  thrown in D:\xampp\htdocs\sea\application\models\auth\permisos.php on line 368

EDITED This solves the above...

function hasPanel($controller,$route){
    includ开发者_如何学JAVAe_once($route);
    $rc = new ReflectionClass($controller);
    if($rc::hasMethod("panel_base")){
        return true;
    }
    return false;
}

But causes this:

Fatal error: Non-static method ReflectionClass::hasMethod() cannot be called statically, assuming $this from incompatible context in D:\xampp\htdocs\sea\application\models\auth\permisos.php on line 373

Some idea?


I'm not entirely sure, but this might be as simple as $rc->hasMethod("panel_base"); You did instantiate a new class. . .


Change

$rc::hasMethod("panel_base")

to

$rc->hasMethod("panel_base")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜