Cakephp 2.0:Htmlhelper在使用Html->脚本()时抛出array_merge()错误

时间:2012-01-03 17:21:27

标签: cakephp html-helper cakephp-2.0

我使用以下代码来实现一些jquery-ui功能:

<?php  $this->Html->script(array(
                              'jquery-ui-1.8.16.custom.min.js',
                              'jquery-1.6.2.min.js'
                                ), 
                           null,
                           array(
                                'inline'=>'false', 
                                'once'=>'true'
                                 ) 
                           ); 
?>

<script>
    jQuery(document).ready(function(){
        $('.cv .collapsable').click(function() {
            $(this).next().toggle('slow');
            return false;
        }).next().hide();
    });
</script>

目标元素/类是元素和嵌套元素。然而,jquery功能正在以php array_merge()错误为代价:

Warning (2): array_merge() [function.array-merge]: Argument #2 is not an array [CORE/Cake/View/Helper/HtmlHelper.php, line 478]
Warning (2): array_merge() [function.array-merge]: Argument #2 is not an array [CORE/Cake/View/Helper/HtmlHelper.php, line 478]
Warning (2): array_merge() [function.array-merge]: Argument #2 is not an array [CORE/Cake/View/Helper/HtmlHelper.php, line 478]

我做错了吗?这是一个错误吗?我曾尝试将<script>标记添加到default.ctp布局中,但无法获取网址。我用cakephp 1.3完成了这个,所以我对我现在遇到的问题感到有些困惑。任何帮助将不胜感激。

更新

所以这是我的完整代码: PHP:

<?php  $this->Html->script(
    array(
       'jquery-1.6.2.min'
    ),
    null,
    array(
        'inline'=>'false', 
    ) 
);  ?>

jquery:

<script>
    jQuery(document).ready(function() {
    $('div.collapsable').click(function() {
        $(this).next().slideToggle("slow");
        return false;
    });
});
</script>

我已经删除了jquery-ui脚本以简化操作 - 当我这样做时,我现在只抛出两个“array_merge”错误。尽管如此,如果我删除'null' - 它甚至不应该存在,因为该函数只需要两个参数 - 我会失去所有功能(错误也会消失)。

但事情变得更加糟糕!

我看了一下cake-&gt; core-&gt; lib-&gt; helper-&gt; htmlhelper并检查了这个函数;它有一行检查$options数组是否是一个bool。如果我改为使用此代码:

<?php  $this->Html->script(
        array(
            'jquery-1.6.2.min'
        ),
        false
);      ?>

我失去了指定inline = trueonce = true的能力,但我至少在没有array_merge()错误的情况下获得了全部功能。这是2.0中的错误吗?

1 个答案:

答案 0 :(得分:0)

the documentation page$this->Html->script()只接受2个参数。删除null,你应该没事。

此外,您不应在脚本文件名末尾包含.js

您的代码应如下所示:

<?php
$this->Html->script(
    array(
       'jquery-ui-1.8.16.custom.min',
       'jquery-1.6.2.min'
    ),
    array(
        'inline'=>'false', 
        'once'=>'true'
    ) 
); 
?>