在钩子

时间:2017-03-25 20:20:39

标签: codeigniter hook

我需要在钩子文件中调用同一个类中的几个函数。

这是我目前的代码:

$hook['post_controller_constructor'] = array(
                                'class'    => 'get_info_general',
                                'function' => 'prepare',
                                'filename' => 'get_info_general.php',
                                'filepath' => 'hooks',
                                'params'   => ''
                                );
$hook['post_controller_constructor'] = array(
                                'class'    => 'get_info_general',
                                'function' => 'get_info_general',
                                'filename' => 'get_info_general.php',
                                'filepath' => 'hooks',
                                'params'   => ''
                                );
$hook['post_controller_constructor'] = array(
                                'class'    => 'get_info_general',
                                'function' =>'get_achievements',
                                'filename' => 'get_info_general.php',
                                'filepath' => 'hooks',
                                'params'   => ''
                                );

不幸的是,只调用了最后一个函数get_achievements。我也尝试过:

$hook['post_controller_constructor'] = array(
                                'class'    => 'get_info_general',
                                'function' => 'prepare',
                                'function' => 'get_info_general',
                                'function' => 'get_achievements',
                                'filename' => 'get_info_general.php',
                                'filepath' => 'hooks',
                                'params'   => ''
                            );

但它给了我相同的结果。

有没有办法让一个接一个地正确调用所有三个函数?我没有找到文档或类似的问题。

1 个答案:

答案 0 :(得分:0)

你只需要制作多维数组。来自docs

  

如果想要对多个脚本使用相同的挂钩点,只需使您的数组声明为多维,如下所示:

$hook['post_controller_constructor'][] = array(
    'class'    => 'get_info_general',
    'function' => 'prepare',
    'filename' => 'get_info_general.php',
    'filepath' => 'hooks',
    'params'   => ''
);
$hook['post_controller_constructor'][] = array(
    'class'    => 'get_info_general',
    'function' => 'get_info_general',
    'filename' => 'get_info_general.php',
    'filepath' => 'hooks',
    'params'   => ''
);
$hook['post_controller_constructor'][] = array(
    'class'    => 'get_info_general',
    'function' =>'get_achievements',
    'filename' => 'get_info_general.php',
    'filepath' => 'hooks',
    'params'   => ''
);
  

注意每个数组索引后的括号:

$hook['post_controller_constructor'][]