首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在钩子中调用同一个类中的几个函数

问在钩子中调用同一个类中的几个函数
EN

Stack Overflow用户
提问于 2017-03-25 20:20:39
回答 1查看 205关注 0票数 1

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

这是我目前的代码:

代码语言:javascript
复制
$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被调用。我也试过:

代码语言:javascript
复制
$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'   => ''
                            );

但这也给了我同样的结果。

是否有办法使这三个函数被正确地一个接一个地调用?我没有找到文件或者类似的问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-25 21:35:38

您只需要创建多维数组。来自文档

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

代码语言:javascript
复制
$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'   => ''
);

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

代码语言:javascript
复制
$hook['post_controller_constructor'][]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43021522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档