我需要在一个钩子文件中从同一个类调用几个函数。
这是我目前的代码:
$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' => ''
);但这也给了我同样的结果。
是否有办法使这三个函数被正确地一个接一个地调用?我没有找到文件或者类似的问题。
发布于 2017-03-25 21:35:38
您只需要创建多维数组。来自文档
如果要对多个脚本使用相同的挂钩点,只需使数组声明为多维,如下所示:
$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'][]https://stackoverflow.com/questions/43021522
复制相似问题