Hi I’m new at yiiframework. My English is bad. DropDownList in cgridview how do I list the country’s cities and do search. For example, when I chose Turkey turkey istanbul or ankara residents of the city who want to list. But I could not. Can you help? Thank you in advance
UyeController.php
<?php
class UyeController extends Controller
{
public function actionArama($kriter)
{
/// arama yapmasını sağlayan kod
$aramasonucu = new Uyeler('search');
$aramasonucu->unsetAttributes();
if(isset($_GET['Uyeler']))
$aramasonucu->attributes=$_GET['Uyeler'];
/// arama yapmasını sağlayan kod bitiş
$this->render('arama', array('aramasonucu'=> $aramasonucu,'kriter'=> $kriter));
}
public function actionEkle()
{
$uyeler = new Uyeler ; // uyeler modelimizi dahil ettik
if(isset($_POST['ekle']))
{
/*echo '<pre>';
var_dump($_POST);
exit;*/
// isset ile formdan gelen verileri kontrol ediyoruz
$uyeler->uye_id = $_POST['uye_id'];
$uyeler->adi = $_POST['adi'];
$uyeler->soyadi = $_POST['soyadi'];
$uyeler->dogum_yeri = $_POST['dogum_yeri'];
$uyeler->dogum_tarihi = $_POST['dogum_tarihi'];
$uyeler->nufus_ili = $_POST['Iller']['ad'];
$uyeler->nufus_ilcesi = $_POST['Ilceler'];
$uyeler->anne_adi = $_POST['anne_adi'];
$uyeler->baba_adi = $_POST['baba_adi'];
$uyeler->tel = $_POST['tel'];
$uyeler->e_posta = $_POST['e_posta'];
$uyeler->kan_grubu = $_POST['kan_grubu'];
$uyeler->cinsiyet = $_POST['cinsiyet'];
$uyeler->adres = $_POST['adres'];
$uyeler->adres_ili = $_POST['Iller']['ilID'];
$uyeler->adres_ilcesi = $_POST['adresIlceler'];
$uyeler->uye_gorevi = $_POST['uye_gorevi'];
$uyeler->uye_kayit_tarihi = $_POST['uye_kayit_tarihi'];
$uyeler->uye_durumu = $_POST['uye_durumu'];
if($uyeler-> save(true))
{
// üye kaydı başarılıysa
$this->render('mesaj',Yii::app()->user->setFlash('success', "Üye Başarı ile eklendi."));
$this->redirect('uye/index');
}
else
{
$this->render('mesaj',Yii::app()->user->setFlash('error', "Hata! Üye Kaydı yapılamadı."));
}
}
else
{
$iller = new Iller();
$this->render('ekle', array('iller'=>$iller));
}
}
public function actionIlcesec()
{
$data = Ilceler::model()->findAll('ilID=:ilID',
array(':ilID'=>$_POST['ilID']));
$data= CHtml::listData($data,'ilceID','ad');
echo "<option value=''>İlçe Seçiniz</option>";
foreach($data as $value=>$name)
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true);
}
public function actionGuncelle()
{
$this->render('guncelle');
}
public function actionIndex()
{
$this->render('index');
}
}
views/uye/arama.php
<?php
$this->breadcrumbs=array(
'Arama',);
$cinsiyetegore = array('1'=>'Erkek', '2'=>'Kadın');
$kangrubunagore = array('1'=>'A Rh (+)','2'=>'A Rh (-)','3'=>'B Rh (+)','4'=>'B Rh (-)','5'=>'AB Rh (+)','6'=>'AB Rh (-)','7'=>'0 Rh (+)','8'=>'0 Rh (-)');
$uyegorevinegore = array('1'=>'Üye','2'=>'Başkan','3'=>'Başkan Yardımcısı','4'=>'Muhasip','5'=>'Sekreter','6'=>'Yedek Üye');
$uyelikdurumunagore = array('1'=>'Aktif','2'=>'Pasif');
switch ($kriter){
case "nufus":
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $aramasonucu->search(),
'filter' => $aramasonucu,
'columns' => array(
array(
'name' => 'id',
'type' => 'raw',
'value' => 'CHtml::encode($data->id)'
),
array(
'name' => 'uye_id',
'type' => 'raw',
'value' => 'CHtml::encode($data->uye_id)'
),
array(
'name' => 'adi',
'type' => 'raw',
'value' => 'CHtml::encode($data->adi)',
),
array(
'name' => 'soyadi',
'type' => 'raw',
'value' => 'CHtml::encode($data->soyadi)',
),
array(
'name' => 'anne_adi',
'type' => 'raw',
'value' => 'CHtml::encode($data->anne_adi)',
),
array(
'name' => 'baba_adi',
'type' => 'raw',
'value' => 'CHtml::encode($data->baba_adi)',
),
array(
'name' => 'dogum_yeri',
'type' => 'raw',
'value' => 'CHtml::encode($data->dogum_yeri)',
),
array(
'name' => 'dogum_tarihi',
'type' => 'raw',
'value' => 'CHtml::encode($data->dogum_tarihi)',
),
array(
'name' => 'nufus_ili',
'type' => 'raw',
'value' => 'CHtml::encode($data->nufus_ili)',
),
array(
'name' => 'nufus_ilcesi',
'type' => 'raw',
'value' => 'CHtml::encode($data->nufus_ilcesi)',
),
array(
'class'=>'CButtonColumn',
),
),
));
break;
case "kisisel":
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $aramasonucu->search(),
'filter' => $aramasonucu,
'columns' => array(
array(
'name' => 'id',
'type' => 'raw',
'value' => 'CHtml::encode($data->id)'
),
array(
'name' => 'tel',
'type' => 'raw',
'value' => 'CHtml::encode($data->tel)'
),
array(
'name' => 'e_posta',
'type' => 'raw',
'value' => 'CHtml::encode($data->e_posta)',
),
array(
'name' => 'kan_grubu',
'type' => 'raw',
'value' => 'CHtml::encode($data->kan_grubu=="1")?("A Rh (+)")<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />"A Rh (-)")<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />"B Rh (+)")',
'filter'=> $kangrubunagore,
),
array(
'name' => 'cinsiyet',
'type' => 'raw',
'value' => 'CHtml::encode($data->cinsiyet=="1")?("Erkek")<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />"Kadın")',
'filter'=> $cinsiyetegore,
),
array(
'name' => 'adres_ili',
'type' => 'raw',
'value' => 'CHtml::encode($data->adres_ili)',
'filter'=> CHtml::listData(Iller::model()->findAll(array('order' => 'ilID')),'ilID','ad'),
),
array(
'name' => 'adres_ilcesi',
'type' => 'raw',
'value' => 'CHtml::encode($data->adres_ilcesi)',
),
array(
'name' => 'uye_gorevi',
'type' => 'raw',
'value' => 'CHtml::encode($data->uye_gorevi)',
'filter'=> $uyegorevinegore,
),
array(
'name' => 'uye_kayit_tarihi',
'type' => 'raw',
'value' => 'CHtml::encode($data->uye_kayit_tarihi)',
),
array(
'name' => 'uye_durumu',
'type' => 'raw',
'value' => 'CHtml::encode($data->uye_durumu=1)',
'filter'=> $uyelikdurumunagore,
),
array(
'class'=>'CButtonColumn',
),
),
));
break;
header('Refresh:3; url='. $this->createUrl('uye/index'));
throw new CHttpException(404,'The specified post cannot be found.');
// $this->render('mesaj',Yii::app()->user->setFlash('error', "Hata! Lütfen arama kriteri seçiniz."));
}
echo "<code><br> Bu sayfa<b> ". Yii::getLogger()->getExecutionTime() . "</b> saniyede oluşturuldu.</code>";
?>
Model/Iller.php
<?php
/**
* This is the model class for table "il".
*
* The followings are the available columns in table 'il':
* @property integer $ilID
* @property string $ad
*/
class Iller extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'il';
}
/**
* @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('ad', 'length', 'max'=>255),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('ilID, ad', '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(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'ilID' => 'Il',
'ad' => 'Ad',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('ilID',$this->ilID);
$criteria->compare('ad',$this->ad,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Iller the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
Model/Ilceler.php
<?php
/**
* This is the model class for table "ilce".
*
* The followings are the available columns in table 'ilce':
* @property integer $ilceID
* @property integer $ilID
* @property string $ad
*/
class Ilceler extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'ilce';
}
/**
* @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('ilID', 'numerical', 'integerOnly'=>true),
array('ad', 'length', 'max'=>255),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('ilceID, ilID, ad', '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(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'ilceID' => 'Ilce',
'ilID' => 'Il',
'ad' => 'Ad',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('ilceID',$this->ilceID);
$criteria->compare('ilID',$this->ilID);
$criteria->compare('ad',$this->ad,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Ilceler the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}