2012-08-13 5 views
0

최근에 Yii와 작업하기 시작했으며 꽤 감명 받았습니다. 그러나, 나는 CGridView를 위해 Ajax URL이 어떻게 생성되는지에 관해 이상한 문제에 직면하고있다. 제가 시도하고있는 것은 처음으로 검색 한 다음 페이지 매김 링크를 클릭하고 다시 검색하여 검색 결과의 일부 페이지로 이동하는 것입니다. 그러나 두 번째 시간 내 그리드 (페이지 매김 링크를 렌더링 할 때 CPagination에 의해 생성되는)이 URL의 절반이 재 작성 볼 수있는 다음과 같은 형식으로많은 수의 열이있는 Yii CGridView의 이상한 동작 - Ajax URL이 엉망입니다.

http://127.0.0.1/myapp/backend/customers/index/XDEBUG_SESSION_START/1/Accounts%5BaccountID%5D//Accounts%5Bname%5D//Accounts%5Baddress%5D/address+1/Accounts%5Bbirthday%5D//Accounts%5BclientType%5D//Accounts%5Bemail%5D//Accounts%5Bbalance%5D//Accounts%5BhasAccess%5D//Accounts_page/3/ajax/yw1?ajax=yw1&Accounts%5BaccountID%5D=&Accounts%5Bname%5D=&Accounts%5Baddress%5D=&Accounts%5Bbirthday%5D=&Accounts%5BclientType%5D=&Accounts%5Bemail%5D=&Accounts%5Bbalance%5D=&Accounts%5BhasAccess%5D=&Accounts_page=1 

을 요청을 전송한다. 그러나 Yii의 gridview js는 새 쿼리를 이전 값과 새 값이있는 URL의 변수 중복으로 끝나는 페이지 매김 링크에 추가합니다. 코드 실행에 $ _GET 변수의 값이 손실됩니다

$_REQUEST[$name]=$_GET[$name]=$value; 

을 인 CUrlManager.php에 라인 (411)에 도달이 결과로서, ($ 값은 다시 쓴에 포함 된 URL의 이전 값을 포함 URL의 일부 (SEO Friendly)). 그리고 이전 검색 결과로 다시 끝납니다.

전 모델

public function behaviors() { 
    return array('CAdvancedArBehavior' => array(
      'class' => 'application.extensions.CAdvancedArBehavior')); 
} 

actionIndex 코드

public function actionIndex() 
    { 
     if (isset($_POST['attribute'])) 
     { 

      $attribute =$_POST['attribute']; 
      $attribute = @explode('_',$attribute); 

       $row = Accounts::model()->findByPk($attribute[1]); 
       if($row != null) 
       { 

           $row->save(); 

       } 




     $dataProvider= new Accounts('search'); 
       $dataProvider->unsetAttributes(); // clear any default values 
     if(isset($_GET['Accounts'])) 
      $dataProvider->attributes=$_GET['Accounts']; 

      $this->render('index', array('model' => $dataProvider)); 
    } 

} 
에서 모델

*/ 
    public function search() { 
     // Warning: Please modify the following code to remove attributes that 
     // should not be searched. 

     $criteria = new CDbCriteria; 

     $criteria->compare('accountID', $this->accountID, true); 
     $criteria->compare('name', $this->name, true); 
     $criteria->compare('balance', $this->balance, true); 
     $criteria->compare('address', $this->address, true); 
     $criteria->compare('birthday', $this->birthday, true); 
     $criteria->compare('clientType', $this->clientType, true); 
     $criteria->compare('email', $this->email, true); 
     $criteria->compare('createAt', $this->createAt, true); 
     $criteria->compare('hasAccess', $this->hasAccess); 

     return new CActiveDataProvider($this, array(
        'criteria' => $criteria, 
       )); 
    } 

행동을

'urlManager' => array(
      'urlFormat' => 'path', 
      'rules' => array(
       '<module:\w+>/<controller:\w+>/<action:\w+>"=>"<module>/<controller>/<action>', 
       '<controller:\w+>/<id:\d+>' => '<controller>/view', 
       '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', 
       '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 
      ), 
      'showScriptName' => false, 
      'caseSensitive' => true, 
     ), 

검색 기능을 사용하고 규칙을

내보기 파일 : 나는 인해 요청 URL에서 쿼리 데이터의 부재로, jtogglecolumn를 사용하려고하면 내 검색 및 페이지 매김을 재설정으로

$this->widget('zii.widgets.grid.CGridView', array(
     'dataProvider' => $model->search(), 
     'filter' => $model, 
     'columns' => array(
      array (
       'name' => 'accountID', 
       'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;') 
      ), 
      array(
       'name' => 'name', 
       'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;') 

      ), 
      array(
       'name' => 'address', 
       'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;') 

      ), 

      array(   // display 'create_time' using an expression 
      'name'=>'birthday', 
      'value'=>'date("M j, Y", strtotime($data->birthday))', 
      'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;') 
      ), 

      array(
       'name' => 'clientType', 
       'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;') 

      ), 

      array(
       'name' => 'email', 
       'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;') 

      ), 
      array(
       'name' => 'balance', 
       'type' => 'raw', 
       'header' => 'Balance', 
       'value' =>'($this->grid->owner->widget("application.extensions.jeditable.DsJEditableWidget", array(
       "model" => $this->grid->dataProvider, 
       "name" => "balance_".$data->accountID, 
       "value" => $data->balance, 
       "jeditable_type" => "text", 
       ),true))', 
      ), 

      array(   // 
       'class' => 'JToggleColumn', 
       'name' => 'hasAccess', 
       'filter' => array(1=>'Yes', 0=>'No'), 
       'checkedButtonImageUrl'=> Yii::App()->baseUrl.'/images/checked.png', // checked image 
       'uncheckedButtonImageUrl'=> Yii::App()->baseUrl.'/images/unchecked.png', // unchecked image 
       'checkedButtonLabel'=>'Yes', // tooltip 
       'uncheckedButtonLabel'=>'No', // tooltip 
       'htmlOptions'=>array('style'=>'text-align:center;min-width:60px;') 
      ), 
     ) 

    ) 

나는

'ajaxUrl' => $this->createUrl('index') 

를 사용하려는 해달라고.

+0

하는 dataProvider의 코드를 게시하시기 바랍니다 도움이되기를 바랍니다. – FabianoLothor

+0

코드를 업데이트했습니다! –

+0

그리드를 렌더링하기 전에 $ _GET에서 unset을 사용해 볼 수 있습니다. – Alex

답변

1

나는 같은 문제를 겪었으며 주위를 놀고 난 후 Nginx 구성이 잘못되었음을 발견했습니다. 이 사람

Nginx.conf이

location/{ 

     index index.php index.html; 
     try_files $uri $uri/ /index.php?$args; 
     #try_files $uri $uri/ /index.php$uri; #Use the default config as above 

    } 
관련 문제