2013-03-28 34 views
1

我刚开始在yii中划伤表面,并且有一段时间让图像滑块扩展工作。我引用了http://www.yiiframework.com/doc/guide/1.1/en/extension.use,并认为我的问题与扩展的初始化有关,但我不确定。我试图使用的最近的扩展是http://www.yiiframework.com/extension/s3slider/yii扩展帮助

到目前为止,我已经下载了扩展,解压缩并放置在/ protected/extensions。我尝试在位于/图像之间滑动的两张图像。我已经放在建议的代码在我/protected/views/layouts/main.php并更新了$图像阵列如下:

<?php 

    $this->widget('application.extensions.s3slider.S3Slider', 
    array(
     'images' => array(
       array('images/giveBack.png', 'Give Back'), 
       array('images/priceGuarantee.png', 'Price Guarantee'), 
     ), 
      'width' => '420', 
      'height' => '300', 
    ) 
);?> 

当我刷新我的网页,我得到以下错误:

PHP notice 
Array to string conversion 
/protected/extensions/s3slider/S3Slider.php(71) 
59   $cssparams = array(
60    'name' => $this->name, 
61    'width' => $this->width, 
62    'height' => $this->height, 
63    'opacity' => $this->opacity, 
64  ); 
65   $clientScript->registerCssFile($baseUrl . '/s3Slider.css.php?data=' . urlencode(base64_encode(serialize($cssparams)))); //http_build_query($cssparams) 
66 
67   $clientScript->registerCoreScript('jquery'); 
68 
69   $clientScript->registerScriptFile($baseUrl . '/s3Slider.js'); 
70 
71   $js = "jQuery('#{$this->name}').s3Slider($options);"; 
72   $cs->registerScript('Yii.S3Slider' . $this->name, $js); 
73   echo $this->makeImages(); 
74  } 
75 
76 } 
77 ?> 

我的堆栈跟踪表明:

/protected/views/layouts/main.php(60): CBaseController->widget("application.extensions.s3slider.S3Slider", array("images" => array(array("images/giveBack.png", "Give Back"), array("images/priceGuarantee.png", "Price Guarantee")), "width" => "420", "height" => "300")) 
55      array('images/priceGuarantee.png', 'Price Guarantee'), 
56    ), 
57    'width' => '420', 
58    'height' => '300', 
59  ) 
60 );?> 
61 
62 <?php 
63 $this->widget('zii.widgets.CBreadcrumbs', array(
64    'links'=>$this->breadcrumbs, 
65  )); ?><!-- breadcrumbs -->  

对此有何指导,将不胜感激!

谢谢。

+0

只需关掉注意错误,否则您的第三方软件将会一直出现这种错误。 – ole

回答

1

您成功安装了此扩展程序,但其中有一个明显的错误。 注意,即在线路52 $options声明

$options = array(); 

然后,它如果不为空检查:

if (!empty($options)) { 
    $options = CJavaScript::encode($options); 
} 

所以$options是空的,所以它不编码为字符串encode,所以在:

$js = "jQuery('#{$this->name}').s3Slider($options);"; 

PHP显示有关数组到字符串转换的注意事项。删除条件检查是否为空,它将编码空数组,并应该工作。作者的扩展可能已经注意到禁用,这是不好的做法。在开发阶段看到通知是明智的。

提示:当你在yii中变得更好时,为jquery插件编写扩展包装将为你拍摄。

+1

谢谢彼得。你的解决方案就像一个魅力。我看到$ options变量,但没有查看cJavaScript :: encode部分。你的时间非常感谢,至少我并没有完全不在意。期待执行你的提示! – user1459766