Search Created By Gii Not Return Any Result


I used gii to create my code (CURD) , So i used search method but my problem if I search on any int field will return

result and every thing is OK .

  • If I serched on text like " Title in English " will not return any result and page still print same results


	public function search()


		// Warning: Please modify the following code to remove attributes that

		// should not be searched.

		$criteria=new CDbCriteria;















    	$criteria->order='news_id desc';

		return new CActiveDataProvider('News', array(




I had no idea why not worked , So I used gii (CURD) to recreate it , but also same problem .

Any idea will help

Thanks in advance

Hi samilo,

Is that "s_text" of your model?

If it is, have you declared "s_text" safe on "search" scenario and created a model instance with "search" scenario for the search parameters?

Hi , softark

yes I declared it and this my code :



     * @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,event_id,s_text,news,country,p_date', 'required','message'=>'يرجى ملئ حقل {attribute}  '),

			array('section_id,course_id, event_id, country, city, active, visits', 'numerical', 'integerOnly'=>true,'message'=>' {attribute}  هذا الحقل من النوع الرقمي فقط '),


			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('title', 'length','min'=>10, 'max'=>66,'tooLong'=>'عد الأحرف أكثر من {max}','tooShort'=>'عدد الأحرف أقل من {min}  '),

        	array('s_text', 'length','min'=>40, 'max'=>230,'tooLong'=>'عد الأحرف أكثر من {max} ','tooShort'=>'عدد الأحرف أقل من {min}'),


        	array('main_img,t_img', 'file','types'=>'jpg,gif,png','allowEmpty'=>true, 'on'=>'update','message'=>'يرجى ملئ حقل {attribute}  '),


        	array('main_img,t_img', 'file','types'=>'jpg,gif,png','allowEmpty'=>false, 'on'=>'insert','message'=>'يرجى ملئ حقل {attribute}  '),


    		array('news_id, section_id, course_id, event_id, s_text, news, main_img, t_img, country, city, i_date, p_date, active, visits', 'safe', 'on'=>'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(

			'course' => array(self::BELONGS_TO, 'Courses', 'course_id'),

			'event' => array(self::BELONGS_TO, 'Events', 'event_id'),

			'country0' => array(self::BELONGS_TO, 'Country', 'country'),

			'city0' => array(self::BELONGS_TO, 'City', 'city'),

			'newsts' => array(self::HAS_MANY, 'Newst', 'news_id'),




     * @return array customized attribute labels (name=>label)


	public function attributeLabels()


		return array(

			'news_id' => 'معرف الخبر',

			'section_id' => 'قسم الخبر',

			'course_id' => 'الكورس',

			'event_id' => 'الحدث',

        	'title'=>'عنوان الخبر',

			's_text' => 'ملخص الخبر',

			'news' => 'الخبر',

			'main_img' => 'الصورة الرئيسية',

			't_img' => 'الصورة المصغرة',

			'country' => 'البلد',

			'city' => 'المدينة',

			'i_date' => 'تاريخ الإدخال',

			'p_date' => 'تاريخ النشر',

			'active' => 'الحالة',

			'visits' => 'الزيارات',



Just for confirmation … is the 4th column displaying "s_text"? Not "title"?

(I’m sorry, but I’m not familiar with your native language …)

4 column is title , s_text not display in grid view, but also i had the same problem with s_text if i used search form

The search on “title” should not work, because your “search” method doesn’t contain

$criteria->compare('title', $this->title, true);

But, the search on "s_text" should work.

Do those attributes come from the columns of the table? Or are they virtual attributes that you have manually defined?

Yah that’s true how I forgot that :blink: :lol: Thank u my friend Softark .

Problem was fixed by u .

But why not create auto by gii ?