ian
ian

Reputation: 12335

How does one track down an error using the YII Framework?

I am learning the Yii Framework and I got this error wich does not really point to the specific pages I am working on or as far as i can tell show me where I should start looking for my problem.

How do I make sense of this? As far as I can see all my 'type_id' references are typed in correctly.

    CException

Description

Property "Project.type_id" is not defined.

Source File

/Users/user/Dropbox/localhost/yii/framework/db/ar/CActiveRecord.php(107)

00095:      */
00096:     public function __get($name)
00097:     {
00098:         if(isset($this->_attributes[$name]))
00099:             return $this->_attributes[$name];
00100:         else if(isset($this->getMetaData()->columns[$name]))
00101:             return null;
00102:         else if(isset($this->_related[$name]))
00103:             return $this->_related[$name];
00104:         else if(isset($this->getMetaData()->relations[$name]))
00105:             return $this->getRelated($name);
00106:         else
00107:             return parent::__get($name);
00108:     }
00109: 
00110:     /**
00111:      * PHP setter magic method.
00112:      * This method is overridden so that AR attributes can be accessed like properties.
00113:      * @param string property name
00114:      * @param mixed property value
00115:      */
00116:     public function __set($name,$value)
00117:     {
00118:         if($this->setAttribute($name,$value)===false)
00119:         {
Stack Trace

#0 /Users/user/Dropbox/localhost/yii/framework/db/ar/CActiveRecord.php(107): CComponent->__get('type_id')
#1 /Users/user/Dropbox/localhost/trackstar/protected/views/project/_view.php(15): CActiveRecord->__get('type_id')
#2 /Users/user/Dropbox/localhost/yii/framework/web/CBaseController.php(119): require('/Users/user/Dro...')
#3 /Users/user/Dropbox/localhost/yii/framework/web/CBaseController.php(88): CBaseController->renderInternal('/Users/user/Dro...', Array, true)
#4 /Users/user/Dropbox/localhost/yii/framework/web/CController.php(748): CBaseController->renderFile('/Users/user/Dro...', Array, true)
#5 /Users/user/Dropbox/localhost/yii/framework/zii/widgets/CListView.php(215): CController->renderPartial('_view', Array)
#6 /Users/user/Dropbox/localhost/yii/framework/zii/widgets/CBaseListView.php(152): CListView->renderItems()
#7 [internal function]: CBaseListView->renderSection(Array)
#8 /Users/user/Dropbox/localhost/yii/framework/zii/widgets/CBaseListView.php(135): preg_replace_callback('/{(\w+)}/', Array, '{summary}?{sort...')
#9 /Users/user/Dropbox/localhost/yii/framework/zii/widgets/CBaseListView.php(121): CBaseListView->renderContent()
#10 /Users/user/Dropbox/localhost/yii/framework/web/CBaseController.php(174): CBaseListView->run()
#11 /Users/user/Dropbox/localhost/trackstar/protected/views/project/index.php(17): CBaseController->widget('zii.widgets.CLi...', Array)
#12 /Users/user/Dropbox/localhost/yii/framework/web/CBaseController.php(119): require('/Users/user/Dro...')
#13 /Users/user/Dropbox/localhost/yii/framework/web/CBaseController.php(88): CBaseController->renderInternal('/Users/user/Dro...', Array, true)
#14 /Users/user/Dropbox/localhost/yii/framework/web/CController.php(748): CBaseController->renderFile('/Users/user/Dro...', Array, true)
#15 /Users/user/Dropbox/localhost/yii/framework/web/CController.php(687): CController->renderPartial('index', Array, true)
#16 /Users/user/Dropbox/localhost/trackstar/protected/controllers/ProjectController.php(148): CController->render('index', Array)
#17 /Users/user/Dropbox/localhost/yii/framework/web/actions/CInlineAction.php(32): ProjectController->actionIndex()
#18 /Users/user/Dropbox/localhost/yii/framework/web/CController.php(300): CInlineAction->run()
#19 /Users/user/Dropbox/localhost/yii/framework/web/filters/CFilterChain.php(129): CController->runAction(Object(CInlineAction))
#20 /Users/user/Dropbox/localhost/yii/framework/web/filters/CFilter.php(41): CFilterChain->run()
#21 /Users/user/Dropbox/localhost/yii/framework/web/CController.php(999): CFilter->filter(Object(CFilterChain))
#22 /Users/user/Dropbox/localhost/yii/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))
#23 /Users/user/Dropbox/localhost/yii/framework/web/filters/CFilterChain.php(126): CInlineFilter->filter(Object(CFilterChain))
#24 /Users/user/Dropbox/localhost/yii/framework/web/CController.php(283): CFilterChain->run()
#25 /Users/user/Dropbox/localhost/yii/framework/web/CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)
#26 /Users/user/Dropbox/localhost/yii/framework/web/CWebApplication.php(320): CController->run('')
#27 /Users/user/Dropbox/localhost/yii/framework/web/CWebApplication.php(120): CWebApplication->runController('project')
#28 /Users/user/Dropbox/localhost/yii/framework/base/CApplication.php(135): CWebApplication->processRequest()
#29 /Users/user/Dropbox/localhost/trackstar/index.php(12): CApplication->run()
#30 {main}
2011-10-17 18:17:18 Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8r DAV/2 PHP/5.3.6 Yii Framework/1.1.2

Upvotes: 1

Views: 1674

Answers (3)

Johnny Tsunami
Johnny Tsunami

Reputation: 11

The problem is that one of your views thinks that your model had this property. For example, I removed a column from a model, but I was calling a view ( _search ) for instance, and this had reference to that column:

<?php echo $form->label($model,'thumbnail'); ?>
25 
<?php echo $form->textField($model,'thumbnail',array('size'=>60,'maxlength'=>255)); ?>

I used:

find . -name "*" | xargs grep -l "my_property"

to track down the offending property

Upvotes: 1

Elvan
Elvan

Reputation: 621

Short answer

If Project class doesn't have object property $type_id, then it will check if type_id column exists in db table for this model.

Long

In addition, if the column still not found then it will try to search method named getType_id(), explanation is here.

Yii implements PHP Magic methods __get($name) and __set($name, $value), allow you, particularly in CActiveRecord, to access attributes that generated from columns in db tables, or other regular attributes from the class using the following syntax .

object->isNewRecord; // '__get()' is called
object->getIsNewRecord(); // regular syntax without magic method

object->isNewRecord = true; // '__set()' is called
object->setIsNewRecord(true);

Upvotes: 1

Oleg
Oleg

Reputation: 7377

In the file /Users/user/Dropbox/localhost/trackstar/protected/views/project/_view.php at line 15 there is something like $project->type_id But in your Project model there is no property "type_id"

Upvotes: 1

Related Questions