我需要从钩子文件中的同一类调用多个函数。
这是我当前的代码:
$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' => ''
);
但它给了我同样的结果。
有没有办法让所有三个函数一个接一个地被正确调用?我没有找到文档或类似的问题。
你只需要制作多维数组。从文档:
如果要对多个脚本使用相同的挂钩点,只需将数组声明设为多维,如下所示:
$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'][]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句