0

我对 Code Igniter 钩子有疑问。我正在触发以下两个钩子。第一个是单例。第二个是普通班。

$hook['post_controller_constructor'] = array(
    'class'    => 'LoggedInUser',
    'function' => 'getInstance',
    'filename' => 'LoggedInUser.php',
    'filepath' => 'hooks',
    'params'   => ""
);

$hook['post_controller_constructor'] = array(
    'class'    => 'SecureController',
    'function' => 'verifyCredentials',
    'filename' => 'SecureController.php',
    'filepath' => 'hooks',
    'params'   => ""
);

当我尝试访问 SecureController 类中的 LoggedInUser::methodName() 时,出现错误。

消息:找不到类“LoggedInUser”

4

1 回答 1

0

对不起,我犯了一个错误。第二个钩子取代了第一个。下面的代码现在是正确的,在数组定义之后有第二个 [] :

$hook['post_controller_constructor'][] = array(
    'class'    => 'LoggedInUser',
    'function' => 'getInstance',
    'filename' => 'LoggedInUser.php',
    'filepath' => 'hooks',
    'params'   => ""
);

$hook['post_controller_constructor'][] = array(
    'class'    => 'SecureController',
    'function' => 'verifyCredentials',
    'filename' => 'SecureController.php',
    'filepath' => 'hooks',
    'params'   => ""
);
于 2019-02-07T19:33:51.403 回答