2013-03-28 130 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