2012-04-04 1 views
5

अरे लोग मैं Yii ढांचे पर काम करना शुरू कर दिया है और मैं Yii ब्लॉग इस ट्यूटोरियल में Yii ढांचे की मूल बातें जानने के लिए ट्यूटोरियल अनुसरण कर रही हूं कि वे एक ClistView का इस्तेमाल किया है पोस्ट देखने में, लेकिन मैं एक अपवाद enter image description hereCListView

हो रही है

$this->breadcrumbs=array(
    'Posts'=>array('index'), 
    $model->post_id, 
); 

$this->menu=array(
    array('label'=>'List Posts', 'url'=>array('index')), 
    array('label'=>'Create Posts', 'url'=>array('create')), 
    array('label'=>'Update Posts', 'url'=>array('update', 'id'=>$model->post_id)), 
    array('label'=>'Delete Posts', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->post_id),'confirm'=>'Are you sure you want to delete this item?')), 
    array('label'=>'Manage Posts', 'url'=>array('admin')), 
); 
?> 

<?php if(!empty($_GET['tag'])) : ?> 
<h1>Posts Tagged with <em><?php echo CHtml::encode($_GET['tag']); ?></em></h1> 
<?php endif; ?> 

<?php $this->widget('zii.widgets.CListView', array(
    'dataProvider' => $model, 
    'itemView' => '_view', 
    'template' => "{items}\n{pager}", 
)); 


:


इस कोड है कि मैं दृश्य फ़ाइल में इस्तेमाल किया है है

यह वही मेरी PostsController होता है:

/** 
    * Displays a particular model. 
    * @param integer $id the ID of the model to be displayed 
    */ 
    public function actionView($id) 
    { 
     $post = $this->loadModel($id); 
     $this->render('view',array(
      'model'=>$post, 
     )); 
    } 

/** 
    * Returns the data model based on the primary key given in the GET variable. 
    * If the data model is not found, an HTTP exception will be raised. 
    * @param integer the ID of the model to be loaded 
    */ 
    public function loadModel($id) 
    { 
     if($this->_model === NULL) 
     { 
      if(Yii::app()->user->isGuest) 
       $condition = 'post_status='.Posts::STATUS_PUBLISHED.' or post_status='.Posts::STATUS_ARCHIVED; 
      else 
       $condition = ''; 

      $this->_model = Posts::model()->findByPk($id, $condition); 

      if($this->_model === NULL) 
       throw new CHttpException(404, 'The requested page does not exist.'); 
     } 

     return $this->_model; 
    } 

मैं नहीं कर सकते पता लगाना, जहां मैं गलत कर रहा हूँ मेरी मदद करें।

उत्तर

4

dataProviderCListView की संपत्ति CActiveDataProvider (या एक अलग डेटा प्रदाता) होना चाहिए।

'dataProvider' => new CActiveDataProvider($model), 

इसके बजाय प्रयास करें।

+0

काम करता है ..... मदद के लिए thnx :) –