Country Ko name ke saath search karwana

Mere pass 2 models hain un main se ek hai users.php or ek hai country.php do no main 1:n (Has Many Relationship banaya hai).

Users.php

id

username

country_id

Country.php

id

country

ab men User ke admin.php main country ko id ke sath nahe per country name ke saath search karwana chahta hun.

Users ke model main Search method ke code ye hai

public function search()

{


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


	// should not be searched.





	$criteria=new CDbCriteria;





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


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


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


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


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


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


         


	return new CActiveDataProvider($this, array(


		'criteria'=>$criteria,


	));


}

or views main

_search.php

ka code ye hai

   <div class="row">


	<?php echo $form->label($model,'country_id'); ?>


	<?php echo $form->textField($model,'country_id'); ?>


</div>

Thanx.

Mansoor Samo

es ko relation based search kehty hian. app es ko es terha sy achieve kr skty hian

apnay model main aik variable banian $country_name ka aur usko es terha estmal karian jis terha name ho raha hia…

Users.php




public $country_name;


// search() kay function main

 $criteria->with = 'country';

 $criteria->compare('country.name', $this->country_name, true);



jahan pay grid ko dekhana hia


array(

'name'=>'country_name',

'value'=>'$data->country->name',

), 

umeed hia app ka masla hal ho jiay ga

shukaria

v helpful posts jo mujhe problems thi yaha akar solve horahe hian…