Blog Demo

As i study yii. I work and test the yii blog demo for me to understand its cycle.

But now. i want to change my database attribute in tbl_post. i want to change the ‘title’ into ‘name’.

I know how to rename it on phpmyadmin (mysql). But i do not know what i need to modify in the codes.

It display error:

Error 500

Property "Post.title" is not defined.

Here is my code:

post/admin

[quote]

<?php

$this->breadcrumbs=array(

'Manage Posts',

);

?>

<h1>Manage Posts</h1>

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'dataProvider'=&gt;&#036;model-&gt;search(),


'filter'=&gt;&#036;model,


'columns'=&gt;array(


	array(


		'name'=&gt;'title',


		'type'=&gt;'raw',


		'value'=&gt;'CHtml::link(CHtml::encode(&#036;data-&gt;title), &#036;data-&gt;url)'


	),


	array(


		'name'=&gt;'status',


		'value'=&gt;'Lookup::item(&quot;PostStatus&quot;,&#036;data-&gt;status)',


		'filter'=&gt;Lookup::items('PostStatus'),


	),


	array(


		'name'=&gt;'create_time',


		'type'=&gt;'datetime',


		'filter'=&gt;false,


	),


	array(


		'class'=&gt;'CButtonColumn',


	),


),

)); ?>

[quote]

models/post

<?php

class Post extends CActiveRecord

{

/**


 * The followings are the available columns in table 'tbl_post':


 * @var integer &#036;id


 * @var string &#036;name


 * @var string &#036;content


 * @var string &#036;tags


 * @var integer &#036;status


 * @var integer &#036;create_time


 * @var integer &#036;update_time


 * @var integer &#036;author_id


 */


const STATUS_DRAFT=1;


const STATUS_PUBLISHED=2;


const STATUS_ARCHIVED=3;





private &#036;_oldTags;





/**


 * Returns the static model of the specified AR class.


 * @return CActiveRecord the static model class


 */


public static function model(&#036;className=__CLASS__)


{


	return parent::model(&#036;className);


}





/**


 * @return string the associated database table name


 */


public function tableName()


{


	return '{{post}}';


}





/**


 * @return array validation rules for model attributes.


 */


public function rules()


{


	// NOTE: you should only define rules for those attributes that


	// will receive user inputs.


	return array(


		array('title, content, status', 'required'),


		array('status', 'in', 'range'=&gt;array(1,2,3)),


		array('title', 'length', 'max'=&gt;128),


		array('tags', 'match', 'pattern'=&gt;'/^[&#092;w&#092;s,]+&#036;/', 'message'=&gt;'Tags can only contain word characters.'),


		array('tags', 'normalizeTags'),





		array('title, status', 'safe', 'on'=&gt;'search'),


	);


}





/**


 * @return array relational rules.


 */


public function relations()


{


	// NOTE: you may need to adjust the relation name and the related


	// class name for the relations automatically generated below.


	return array(


		'author' =&gt; array(self::BELONGS_TO, 'User', 'author_id'),


		'comments' =&gt; array(self::HAS_MANY, 'Comment', 'post_id', 'condition'=&gt;'comments.status='.Comment::STATUS_APPROVED, 'order'=&gt;'comments.create_time DESC'),


		'commentCount' =&gt; array(self::STAT, 'Comment', 'post_id', 'condition'=&gt;'status='.Comment::STATUS_APPROVED),


	);


}





/**


 * @return array customized attribute labels (name=&gt;label)


 */


public function attributeLabels()


{


	return array(


		'id' =&gt; 'Id',


		'title' =&gt; 'Title',


		'content' =&gt; 'Content',


		'tags' =&gt; 'Tags',


		'status' =&gt; 'Status',


		'create_time' =&gt; 'Create Time',


		'update_time' =&gt; 'Update Time',


		'author_id' =&gt; 'Author',


	);


}





/**


 * @return string the URL that shows the detail of the post


 */


public function getUrl()


{


	return Yii::app()-&gt;createUrl('post/view', array(


		'id'=&gt;&#036;this-&gt;id,


		'title'=&gt;&#036;this-&gt;title,


	));


}





/**


 * @return array a list of links that point to the post list filtered by every tag of this post


 */


public function getTagLinks()


{


	&#036;links=array();


	foreach(Tag::string2array(&#036;this-&gt;tags) as &#036;tag)


		&#036;links[]=CHtml::link(CHtml::encode(&#036;tag), array('post/index', 'tag'=&gt;&#036;tag));


	return &#036;links;


}





/**


 * Normalizes the user-entered tags.


 */


public function normalizeTags(&#036;attribute,&#036;params)


{


	&#036;this-&gt;tags=Tag::array2string(array_unique(Tag::string2array(&#036;this-&gt;tags)));


}





/**


 * Adds a new comment to this post.


 * This method will set status and post_id of the comment accordingly.


 * @param Comment the comment to be added


 * @return boolean whether the comment is saved successfully


 */


public function addComment(&#036;comment)


{


	if(Yii::app()-&gt;params['commentNeedApproval'])


		&#036;comment-&gt;status=Comment::STATUS_PENDING;


	else


		&#036;comment-&gt;status=Comment::STATUS_APPROVED;


	&#036;comment-&gt;post_id=&#036;this-&gt;id;


	return &#036;comment-&gt;save();


}





/**


 * This is invoked when a record is populated with data from a find() call.


 */


protected function afterFind()


{


	parent::afterFind();


	&#036;this-&gt;_oldTags=&#036;this-&gt;tags;


}





/**


 * This is invoked before the record is saved.


 * @return boolean whether the record should be saved.


 */


protected function beforeSave()


{


	if(parent::beforeSave())


	{


		if(&#036;this-&gt;isNewRecord)


		{


			&#036;this-&gt;create_time=&#036;this-&gt;update_time=time();


			&#036;this-&gt;author_id=Yii::app()-&gt;user-&gt;id;


		}


		else


			&#036;this-&gt;update_time=time();


		return true;


	}


	else


		return false;


}





/**


 * This is invoked after the record is saved.


 */


protected function afterSave()


{


	parent::afterSave();


	Tag::model()-&gt;updateFrequency(&#036;this-&gt;_oldTags, &#036;this-&gt;tags);


}





/**


 * This is invoked after the record is deleted.


 */


protected function afterDelete()


{


	parent::afterDelete();


	Comment::model()-&gt;deleteAll('post_id='.&#036;this-&gt;id);


	Tag::model()-&gt;updateFrequency(&#036;this-&gt;tags, '');


}





/**


 * Retrieves the list of posts based on the current search/filter conditions.


 * @return CActiveDataProvider the data provider that can return the needed posts.


 */


public function search()


{


	&#036;criteria=new CDbCriteria;





	&#036;criteria-&gt;compare('title',&#036;this-&gt;title,true);





	&#036;criteria-&gt;compare('status',&#036;this-&gt;status);





	return new CActiveDataProvider('Post', array(


		'criteria'=&gt;&#036;criteria,


		'sort'=&gt;array(


			'defaultOrder'=&gt;'status, update_time DESC',


		),


	));


}

}[/b]

Somebody help me. Thanks

Change in attributeLabels() in models,you can change any name there.Code part will be same,in display it will change.

I fixed it already…

Good. ;)

Tnx a lot Mr. :D