2014-04-13 33 views
0

每個人我正在一個項目,允許用戶上傳和下載數據。我想在CGridView中只顯示用戶自己上傳的數據。 這裏是我的關係表 enter image description hereYii - 如何在CGridView中顯示用戶自己上傳的數據?

我試圖編輯我的網頁 - >的意見/文件/ myUploads.php

<?php 
$isMine=Yii::app()->user->id; // I have tried this 
if($isMine){ 
    $this->widget('zii.widgets.CGridView',array(
    'id'=>'file-grid', 
    'dataProvider'=>$model->search(), 
    //'filter'=>$model, 
    'columns'=>array(
     'name' 
     'description', 
     'category' 
     'uploader' 
     'upload_date', 
     array(
      'header'=>'Actions', 
      'class'=>'bootstrap.widgets.TbButtonColumn', 
       'template'=>'{delete}', //'visible'=> (Yii::app()->user->getLevel()==1), 
       'deleteConfirmation'=>"js: 'Are you want to delete '+$(this).parent().parent().children(':first-child').text()+ '?'",   
       'buttons'=>array(
        'delete' => array(
         'visible'=> '$data->pengunggah==Yii::app()->user->id', 
        ), 
       ) 
     ), 
    ), 
)); } 
?> 

我已經試過以上驗證碼,但是網頁仍然顯示所有數據,而不是用戶自己的數據。

我試圖在FileController.php編輯myUpload功能太

public function actionMyUpload() 
{ 
    $isMine=Yii::app()->user->id; // I have tried this 
    if($isMine){ 
     $model=new File('search'); 
     $model->unsetAttributes(); // clear any default values 
     if(isset($_GET['File'])) 
      $model->attributes=$_GET['File']; 

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

但仍然顯示的所有數據。

任何人都可以幫助我嗎?非常感謝。

回答

1

恢復所有更改回來,打開你的模型類文件即「File.php」並在搜索加入這一行()功能:

$criteria=new CDbCriteria; 
// Simply add this line 
$criteria->addCondition('id_user='.Yii::app()->user->id); 
相關問題