Yii Framework Forum: Country Ko name ke saath search karwana - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Country Ko name ke saath search karwana

#1 User is offline   Mansoor Samo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 07-October 14

Posted 07 October 2014 - 12:56 AM

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

Attached File(s)


0

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 589
  • Joined: 26-November 10
  • Location:Sialkot, Pakistan

Posted 30 October 2014 - 04:25 AM

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
Cheers
PeRoChAk
Cheap Domain & Hosting - Web & App Design - Web Application Development

My Page
0

#3 User is offline   innocenteyes 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 10-August 15

Posted 19 November 2015 - 07:50 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users