【问题标题】:yii extension assistanceyii 扩展协助
【发布时间】:2013-03-19 09:26:23
【问题描述】:

我刚刚开始在 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 -->    

任何关于这方面的指导将不胜感激!

谢谢。

【问题讨论】:

  • 只需关闭通知错误,否则您将始终在 3rd 方软件中遇到此类错误。

标签: php jquery oop yii yii-extensions


【解决方案1】:

您已成功安装此扩展程序,但是其中有一个明显的错误。 请注意,在第 52 行声明了 $options

$options = array();

如果不为空则检查:

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

所以$options是空的,所以没有用encode编码成字符串,所以在:

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

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

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

【讨论】:

  • 谢谢彼得。您的解决方案就像一个魅力。我看到了 $options 变量,但没有查看 cJavaScript::encode 部分。非常感谢您的时间,至少我并没有完全失去理智。期待执行您的提示!
猜你喜欢
  • 1970-01-01
  • 2011-06-21
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多