# CodeIgniter 同一挂钩点的多次引用

**URL:** <https://www.isharkfly.com/t/codeigniter/4185>\
**Category:** PHP\
**Created:** [January 6, 2014, 1:05am UTC](https://www.isharkfly.com/t/codeigniter/4185 "2014-01-06T01:05:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [January 6, 2014, 1:05am UTC](https://www.isharkfly.com/t/codeigniter/4185/1 "2014-01-06T01:05:33Z")

</div>

如果你想在同一个挂钩点引用多个脚本,最简单的方式就是把你的数组定义成二维的,像这样:[code]$hook[‘pre\_controller’] = array(  
‘class’ =\> ‘MyClass’,  
‘function’ =\> ‘Myfunction’,  
‘filename’ =\> ‘Myclass.php’,  
‘filepath’ =\> ‘hooks’,  
‘params’ =\> array(‘beer’, ‘wine’, ‘snacks’)  
);

$hook[‘pre\_controller’] = array(  
‘class’ =\> ‘MyOtherClass’,  
‘function’ =\> ‘MyOtherfunction’,  
‘filename’ =\> ‘Myotherclass.php’,  
‘filepath’ =\> ‘hooks’,  
‘params’ =\> array(‘red’, ‘yellow’, ‘blue’)  
);[/code]注意在每个数组索引后面的中括号:`$hook['pre_controller'][]`这允许你的多个脚本拥有相同的挂钩点。你定义数组的顺序将是程序执行的顺序.
