在挂钩中调用相同 class 中的多个函数
call several functions within same class in hooks
我需要从挂钩文件中的同一个 class 调用多个函数。
这是我当前的代码:
$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' => ''
);
但它给了我相同的结果。
有什么方法可以让所有三个函数一个接一个地被正确调用?我没有找到文档或类似问题。
你只需要制作多维数组。来自 docs:
If want to use the same hook point with more than one script, simply make your array declaration multi-dimensional, like this:
$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' => ''
);
Notice the brackets after each array index:
$hook['post_controller_constructor'][]
我需要从挂钩文件中的同一个 class 调用多个函数。
这是我当前的代码:
$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' => ''
);
但它给了我相同的结果。
有什么方法可以让所有三个函数一个接一个地被正确调用?我没有找到文档或类似问题。
你只需要制作多维数组。来自 docs:
If want to use the same hook point with more than one script, simply make your array declaration multi-dimensional, like this:
$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' => ''
);
Notice the brackets after each array index:
$hook['post_controller_constructor'][]