2013-08-06 85 views
0

我無法在加載時將多選控件的左側列表設置爲空模式。當我將null值設置爲左側列表時,它顯示錯誤。這是我的代碼:在Yii中自定義Xmultiselect

$this->widget('ext.widgets.multiselects.XMultiSelects', array(
            'leftTitle' => '', 
            'leftName' => 'Certificate[selected][]', 
            'leftList' => SpecificCertification::model()->findCertificate(),// here I need to make the list empty 
            'rightTitle' => '', 
            'rightName' => 'Certificate[all][]', 
            'rightList' => SpecificCertification::model()->findCertificates(), 
            'size' => 10, 
           )); 

如何讓左列表爲空?

回答

0

您需要打開文件窗口小部件XMultiSelects.php並對其進行修改以滿足您的需要

public function init() 
    { 
/* Comment out the below validation 
     if(!isset($this->leftList)) 
     { 
      throw new CHttpException(500,'"leftList" have to be set!'); 
     } 
     if(!isset($this->rightList)) 
     { 
      throw new CHttpException(500,'"rightList" have to be set!'); 
     } 
*/ 
    } 

爲leftList和rightList添加驗證,如下面

if($this->leftList){ 
      foreach($this->leftList as $value=>$label) 
      { 
       echo "<option value=\"{$value}\">{$label}</option>\n"; 
      } 
     } 

if($this->rightList){ 
     foreach($this->rightList as $value=>$label) 
      { 
       echo "<option value=\"{$value}\">{$label}</option>\n"; 
      } 
     } 

之後,你可以像他們那樣爲他們設置null