3 คำตอบ
เรื่องมีอยู่ว่า ผมได้แก้โคด _form.php ของ research ซึ่งเดิมเป็น textfield จะเปลี่ยนให้เป็น dropDownlist ที่ดึงข้อมูลจาก ตาราง researcher
ซึ่งเมื่อแก้จาก textfield เป็น dropDownlist เกิด error ขึ้น**
โคดที่ผมใช้ครับ
<div>
<?php echo $form->labelEx($model,'idresearcher'); ?>
<?php echo $form->textField($model,'idresearcher'); ?>
<?php echo $form->error($model,'idresearcher'); ?>
</div>
ไม่ทราบว่ากรณีอย่างนี้เกิดเพราะอะไรครับ
** ---------------------error --------------------
CException
Property "Research.researcher" is not defined.
/home/rdkkc/public_html/framework/db/ar/CActiveRecord.php(145)
133 */
134 public function __get($name)
135 {
136 if(isset($this->_attributes[$name]))
137 return $this->_attributes[$name];
138 elseif(isset($this->getMetaData()->columns[$name]))
139 return null;
140 elseif(isset($this->_related[$name]))
141 return $this->_related[$name];
142 elseif(isset($this->getMetaData()->relations[$name]))
143 return $this->getRelated($name);
144 else
145 return parent::__get($name);
146 }
147
148 /**
149 * PHP setter magic method.
150 * This method is overridden so that AR attributes can be accessed like properties.
151 * @param string $name property name
152 * @param mixed $value property value
153 */
154 public function __set($name,$value)
155 {
156 if($this->setAttribute($name,$value)===false)
157 {
Stack Trace
| #0 | + /home/rdkkc/public_html/framework/db/ar/CActiveRecord.php(145): CComponent->__get("researcher") |
| #1 |
+ /home/rdkkc/public_html/framework/web/helpers/CHtml.php(2728): CActiveRecord->__get("researcher") |
| #2 |
+ /home/rdkkc/public_html/framework/web/helpers/CHtml.php(1981): CHtml::resolveValue(Research, "researcher") |
| #3 |
+ /home/rdkkc/public_html/framework/web/widgets/CActiveForm.php(914): CHtml::activeDropDownList(Research, "researcher", array("" => "พลนิกรณ์"), array("empty" => "เลือกการแสดงผล")) |
| #4 |
– /home/rdkkc/public_html/protected/views/research/_form.php(56): CActiveForm->dropDownList(Research, "researcher", array("" => "พลนิกรณ์"), array("empty" => "เลือกการแสดงผล"))51
52 <div>
53 <?php echo $form->labelEx($model,'researcher'); ?>
54 <?php echo $form->dropDownList($model,'researcher',
55 CHtml::listData(Researcher::model()->findAll(),'id','name'),
56 array('empty' => 'เลือกการแสดงผล'));?>
57
58 <?php echo $form->error($model,'researcher'); ?>
59 </div>
60
61 <div>
|
| #5 | + /home/rdkkc/public_html/framework/web/CBaseController.php(126): require("/home/rdkkc/public_html/protected/views/research/_form.php") |
| #6 | + /home/rdkkc/public_html/framework/web/CBaseController.php(95): CBaseController->renderInternal("/home/rdkkc/public_html/protected/views/research/_form.php", array("model" => Research), true) |
| #7 | + /home/rdkkc/public_html/framework/web/CController.php(869): CBaseController->renderFile("/home/rdkkc/public_html/protected/views/research/_form.php", array("model" => Research), true) |
| #8 | – /home/rdkkc/public_html/protected/views/research/create.php(18): CController->renderPartial("_form", array("model" => Research))13 );
14 ?>
15
16 <h1>Create Research</h1>
17
18 <?php $this->renderPartial('_form', array('model'=>$model)); ?>
|
| #9 | + /home/rdkkc/public_html/framework/web/CBaseController.php(126): require("/home/rdkkc/public_html/protected/views/research/create.php") |
| #10 | + /home/rdkkc/public_html/framework/web/CBaseController.php(95): CBaseController->renderInternal("/home/rdkkc/public_html/protected/views/research/create.php", array("model" => Research), true) |
| #11 | + /home/rdkkc/public_html/framework/web/CController.php(869): CBaseController->renderFile("/home/rdkkc/public_html/protected/views/research/create.php", array("model" => Research), true) |
| #12 | + /home/rdkkc/public_html/framework/web/CController.php(782): CController->renderPartial("create", array("model" => Research), true) |
| #13 | – /home/rdkkc/public_html/protected/controllers/ResearchController.php(79): CController->render("create", array("model" => Research))74 $this->redirect(array('view','id'=>$model->idResearch));
75 }
76
77 $this->render('create',array(
78 'model'=>$model,
79 ));
80 }
81
82 /**
83 * Updates a particular model.
84 * If update is successful, the browser will be redirected to the 'view' page.
|
| #14 | + /home/rdkkc/public_html/framework/web/actions/CInlineAction.php(49): ResearchController->actionCreate() |
| #15 | + /home/rdkkc/public_html/framework/web/CController.php(308): CInlineAction->runWithParams(array("r" => "research/create")) |
| #16 | + /home/rdkkc/public_html/framework/web/filters/CFilterChain.php(133): CController->runAction(CInlineAction) |
| #17 | + /home/rdkkc/public_html/framework/web/filters/CFilter.php(40): CFilterChain->run() |
| #18 | – /home/rdkkc/public_html/framework/web/CController.php(1145): CFilter->filter(CFilterChain)1140 */
1141 public function filterAccessControl($filterChain)
1142 {
1143 $filter=new CAccessControlFilter;
1144 $filter->setRules($this->accessRules());
1145 $filter->filter($filterChain);
1146 }
1147
1148 /**
1149 * Returns a persistent page state value.
1150 * A page state is a variable that is persistent across POST requests of the same page.
|
| #19 | + /home/rdkkc/public_html/framework/web/filters/CInlineFilter.php(58): CController->filterAccessControl(CFilterChain) |
| #20 | + /home/rdkkc/public_html/framework/web/filters/CFilterChain.php(130): CInlineFilter->filter(CFilterChain) |
| #21 | + /home/rdkkc/public_html/framework/web/CController.php(291): CFilterChain->run() |
| #22 | + /home/rdkkc/public_html/framework/web/CController.php(265): CController->runActionWithFilters(CInlineAction, array("accessControl", "postOnly + delete")) |
| #23 | + /home/rdkkc/public_html/framework/web/CWebApplication.php(282): CController->run("create") |
| #24 | + /home/rdkkc/public_html/framework/web/CWebApplication.php(141): CWebApplication->runController("research/create") |
| #25 | + /home/rdkkc/public_html/framework/base/CApplication.php(184): CWebApplication->processRequest() |
| #26 | + /home/rdkkc/public_html/index.php(13): CApplication->run() |
2015-08-07 21:52:26 Apache/2.4.10 (Debian) Yii Framework/1.1.16
มันบอกว่าไม่มี attribute researcher ครับ ดูจาก code ข้างบนจะเห็นว่า attribute คือ idresearcher ครับ เปลี่ยนตรงนี้ครับ
dropDownList($model,'idresearcher',
ขอบคุณครับ