2015-05-18 72 views
-1

我使用Yii框架,我想的東西添加到我的數據庫,我得到這個錯誤:屬性「CGridView.data」沒有定義

  CException 

Property "CGridView.data" is not defined. 

C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CWidgetFactory.php(161) 

149   if(isset($this->widgets[$className])) 
150    $properties=$properties===array() ? $this->widgets[$className] : CMap::mergeArray($this->widgets[$className],$properties); 
151   if($this->enableSkin) 
152   { 
153    if($this->skinnableWidgets===null || in_array($className,$this->skinnableWidgets)) 
154    { 
155     $skinName=isset($properties['skin']) ? $properties['skin'] : 'default'; 
156     if($skinName!==false && ($skin=$this->getSkin($className,$skinName))!==array()) 
157      $properties=$properties===array() ? $skin : CMap::mergeArray($skin,$properties); 
158    } 
159   } 
160   foreach($properties as $name=>$value) 
161    $widget->$name=$value; 
162   return $widget; 
163  } 
164 
165  /** 
166  * Returns the skin for the specified widget class and skin name. 
167  * @param string $className the widget class name 
168  * @param string $skinName the widget skin name 
169  * @return array the skin (name=>value) for the widget 
170  */ 
171  protected function getSkin($className,$skinName) 
172  { 
173   if(!isset($this->_skins[$className][$skinName])) 
Stack Trace 
#0 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CWidgetFactory.php(161): CComponent->__set("data", Document) 
#1 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CBaseController.php(146): CWidgetFactory->createWidget(DocumentController, "zii.widgets.grid.CGridView", array("data" => Document, "attributes" => array("id", "file_id", "timestamp", "description", ...))) 
#2 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CBaseController.php(180): CBaseController->createWidget("zii.widgets.grid.CGridView", array("data" => Document, "attributes" => array("id", "file_id", "timestamp", "description", ...))) 
#3 
– C:\wamp\www\testdrive - 18-05-2015\private\protected\views\document\view.php(30): CBaseController->widget("zii.widgets.grid.CGridView", array("data" => Document, "attributes" => array("id", "file_id", "timestamp", "description", ...))) 
25   'file_id', 
26   'timestamp', 
27   'description', 
28   'content', 
29 ), 
30)); ?> 
#4 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CBaseController.php(126): require("C:\wamp\www\testdrive - 18-05-2015\private\protected\views\docum...") 
#5 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CBaseController.php(95): CBaseController->renderInternal("C:\wamp\www\testdrive - 18-05-2015\private\protected\views\docum...", array("model" => Document), true) 
#6 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CController.php(869): CBaseController->renderFile("C:\wamp\www\testdrive - 18-05-2015\private\protected\views\docum...", array("model" => Document), true) 
#7 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CController.php(782): CController->renderPartial("view", array("model" => Document), true) 
#8 
– C:\wamp\www\testdrive - 18-05-2015\private\protected\controllers\DocumentController.php(56): CController->render("view", array("model" => Document)) 
51  */ 
52  public function actionView($id) 
53  { 
54   $this->render('view',array(
55    'model'=>$this->loadModel($id), 
56  )); 
57  } 
58 
59  /** 
60  * Creates a new model. 
61  * If creation is successful, the browser will be redirected to the 'view' page. 
#9 
unknown(0): DocumentController->actionView("13") 
#10 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\actions\CAction.php(109): ReflectionMethod->invokeArgs(DocumentController, array("13")) 
#11 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\actions\CInlineAction.php(47): CAction->runWithParamsInternal(DocumentController, ReflectionMethod, array("id" => "13")) 
#12 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CController.php(308): CInlineAction->runWithParams(array("id" => "13")) 
#13 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\filters\CFilterChain.php(133): CController->runAction(CInlineAction) 
#14 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\filters\CFilter.php(40): CFilterChain->run() 
#15 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CController.php(1145): CFilter->filter(CFilterChain) 
#16 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\filters\CInlineFilter.php(58): CController->filterAccessControl(CFilterChain) 
#17 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\filters\CFilterChain.php(130): CInlineFilter->filter(CFilterChain) 
#18 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CController.php(291): CFilterChain->run() 
#19 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CController.php(265): CController->runActionWithFilters(CInlineAction, array("accessControl", "postOnly + delete")) 
#20 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CWebApplication.php(282): CController->run("view") 
#21 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\web\CWebApplication.php(141): CWebApplication->runController("document/view") 
#22 
+ C:\wamp\www\testdrive - 18-05-2015\yii\framework\base\CApplication.php(184): CWebApplication->processRequest() 
#23 
– C:\wamp\www\testdrive - 18-05-2015\public\index.php(18): CApplication->run() 
13 defined('YII_DEBUG') or define('YII_DEBUG',true); 
14 // specify how many levels of call stack should be shown in each log message 
15 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3); 
16 
17 require_once($yii); 
18 Yii::createWebApplication($config)->run(); 
19 ?> 

我不知道哪裏出了問題究竟。我的數據庫中有4個其他表,這是唯一一個不能工作的表,並且出現錯誤。 你可以向我解釋出什麼問題嗎?是從我的數據庫中的問題??

後來它將記錄添加到數據庫中,即使它之前發生錯誤。

+0

發佈您的Cgridview代碼admin.php文件 –

回答

0

CGridView按照表格顯示數據項目列表。

由於CGidView沒有屬性「數據」而異常。類有屬性'dataProvider'。這是一個CGridView的簡單例子。您可以使用GII從您的模型生成示例。

// in your view. 
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'document', 
    // you can't use key 'data' here 
    'dataProvider' => $document->search(), // @var Document $document - your model 
    'columns' => array(
     'id', 
     // ... other properties 
    ) 
)); 

// in model Document 
public function search() 
{ 
    $criteria = new CDbCriteria(); 

    $criteria->compare('id',$this->id); 
    //$criteria->compare('one_more_poperty', $this->one_more_poperty); 
    ... 

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