cgridview search not working.

[font="Courier New"]I have this problem from

i have two tables


-------------- … ------------




here’s my model

class TeacherStatus extends CActiveRecord


public $search_name;

	public function tableName()


		return 'teacher_status';


	public function rules()


		return array(

			array('user_id, login_date', 'required'),

			array('user_id', 'numerical', 'integerOnly'=>true),

			array('login_date', 'length', 'max'=>255),

			array('id, tid, login_date', 'safe', 'on'=>'search'),



	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(

			'teachers2'=>array( self::BELONGS_TO, 'teachers2', 'tid' ),



	public function attributeLabels()


		return array(

			'id' => 'ID',

			'tid' => 'Tid',

			'status' => 'Status',

			'status_date' => 'Status Date',



	public function search()


		$criteria=new CDbCriteria;

		$criteria->with = array( 'teachers2' );

		$criteria->compare( 'user_fname', $this->search_name, TRUE );







		return new CActiveDataProvider($this, array(






                'desc'=>'teachers2.user_fname DESC',







	public static function get_teacher_name($id){

		$con = Yii::app()->db;

		$query = $con->createcommand("SELECT concat(user_fname,' ',user_lname) as name FROM user_account WHERE user_id = $id");

		$count = $query->query();


			$wew = $query->queryall();

			return $wew[0]['name'];

		} else {

			return null;



	public static function model($className=__CLASS__)


		return parent::model($className);



my gridview




 'value' => 'CHtml::value($data,"teachers2.user_fname")',

 'filter' => CHtml::activeTextField($model, 'search_name'),


filter search_name is not working.

any idea why?


HI Juliano

Thank you for continuing in the forum in stead of discussing in the wiki comments ;-).

To avoid your issue I have written an extension: .

A first issue that I see in your code above is that ‘search_name’ is not listed as a safe attribute - you have to make it safe.