Search Created By Gii Not Return Any Result

Hi

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

Model:




	public function search()

	{

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

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('news_id',$this->news_id);

		$criteria->compare('section_id',$this->section_id);

		$criteria->compare('course_id',$this->course_id);

		$criteria->compare('event_id',$this->event_id);

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

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

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

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

		$criteria->compare('country',$this->country);

		$criteria->compare('city',$this->city);

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

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

		$criteria->compare('active',$this->active);

		$criteria->compare('visits',$this->visits);

    	$criteria->order='news_id desc';

		return new CActiveDataProvider('News', array(

			'criteria'=>$criteria,

		));

	}




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 :

Model




	/**

     * @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 ?