yii扩展援助

时间:2013-03-28 19:19:17

标签: php jquery oop yii yii-extensions

我刚刚开始在yii中划伤表面并且正好让任何图像滑块扩展工作。我引用了http://www.yiiframework.com/doc/guide/1.1/en/extension.use并认为我的问题与扩展的初始化有关,但我不确定。我尝试使用的最新扩展程序是http://www.yiiframework.com/extension/s3slider/

到目前为止,我已经下载了扩展程序,解压缩并放入/ protected / extensions。我有两张图像,我试图在位于/ images之间滑动。我已将建议的代码放在我的/protected/views/layouts/main.php中,并更新了$ images数组,如下所示:

<?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 -->    

非常感谢任何关于此的指导!

谢谢。

1 个答案:

答案 0 :(得分:1)

您已成功安装此扩展程序,但其中存在明显的错误。 注意,第52行$options被声明为

$options = array();

然后检查是否为空:

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

因此$options为空,因此未使用encode编码为字符串,因此在:

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

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

提示:当你在yii中变得更好时,为你编写jquery插件的扩展包装器会很快。