Hi, I’m English bad. was taking data from different database with caller ID name of the town you want to show in the grid.
- Model: Iller
colums:
ilID (PK)
ad
- Model :Ilceler
colums:
ilceID (PK)
ilID
ad
3.Model Uyeler :
<?php
/**
* This is the model class for table "uyeler".
*
* The followings are the available columns in table 'uyeler':
* @property integer $id
* @property string $uye_id
* @property string $adi
* @property string $soyadi
* @property string $dogum_yeri
* @property string $dogum_tarihi
* @property integer $nufus_ili
* @property integer $nufus_ilcesi
* @property string $anne_adi
* @property string $baba_adi
* @property string $tel
* @property string $e_posta
* @property integer $kan_grubu
* @property integer $cinsiyet
* @property string $adres
* @property integer $adres_ilcesi
* @property integer $adres_ili
* @property integer $uye_gorevi
* @property string $uye_kayit_tarihi
* @property integer $uye_durumu
*/
class Uyeler extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'uyeler';
}
/**
* @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('uye_id, adi, soyadi, dogum_yeri, dogum_tarihi, nufus_ili, nufus_ilcesi, anne_adi, baba_adi, tel, cinsiyet, adres, adres_ilcesi, adres_ili, uye_gorevi, uye_kayit_tarihi, uye_durumu', 'required'),
array('nufus_ili, nufus_ilcesi, kan_grubu, cinsiyet, adres_ilcesi, adres_ili, uye_gorevi, uye_durumu', 'numerical', 'integerOnly'=>true),
array('uye_id, tel', 'length', 'max'=>11),
array('adres', 'length', 'max'=>255),
array('e_posta', 'safe'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, uye_id, adi, soyadi, dogum_yeri, dogum_tarihi, nufus_ili, nufus_ilcesi, anne_adi, baba_adi, tel, e_posta, kan_grubu, cinsiyet, adres, adres_ilcesi, adres_ili, uye_gorevi, uye_kayit_tarihi, uye_durumu', '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(
'id' => 'ID',
'uye_id' => 'Üye No',
'adi' => 'Adı',
'soyadi' => 'Soyadı',
'dogum_yeri' => 'Doğum Yeri',
'dogum_tarihi' => 'Doğum Tarihi',
'nufus_ili' => 'Nüf.Kayıtlı olduğu İl',
'nufus_ilcesi' => 'Nüf.Kayıtlı olduğu İlçe',
'anne_adi' => 'Anne Adı',
'baba_adi' => 'Baba Adı',
'tel' => 'Telefon',
'e_posta' => 'E-Posta',
'kan_grubu' => 'Kan Grubu',
'cinsiyet' => 'Cinsiyet',
'adres' => 'Adres',
'adres_ilcesi' => 'Adres İlçesi',
'adres_ili' => 'Adres İli',
'uye_gorevi' => 'Üye Görevi',
'uye_kayit_tarihi' => 'Üye Kayıt Tarihi',
'uye_durumu' => 'Üyelik Durumu',
);
}
/**
* 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('id',$this->id);
$criteria->compare('uye_id',$this->uye_id,true);
$criteria->compare('adi',$this->adi,true);
$criteria->compare('soyadi',$this->soyadi,true);
$criteria->compare('dogum_yeri',$this->dogum_yeri,true);
$criteria->compare('dogum_tarihi',$this->dogum_tarihi,true);
$criteria->compare('nufus_ili',$this->nufus_ili);
$criteria->compare('nufus_ilcesi',$this->nufus_ilcesi);
$criteria->compare('anne_adi',$this->anne_adi,true);
$criteria->compare('baba_adi',$this->baba_adi,true);
$criteria->compare('tel',$this->tel,true);
$criteria->compare('e_posta',$this->e_posta,true);
$criteria->compare('kan_grubu',$this->kan_grubu);
$criteria->compare('cinsiyet',$this->cinsiyet);
$criteria->compare('adres',$this->adres,true);
$criteria->compare('adres_ilcesi',$this->adres_ilcesi);
$criteria->compare('adres_ili',$this->adres_ili);
$criteria->compare('uye_gorevi',$this->uye_gorevi);
$criteria->compare('uye_kayit_tarihi',$this->uye_kayit_tarihi,true);
$criteria->compare('uye_durumu',$this->uye_durumu);
/* if(!empty($this->uye_kayit_tarihi))
{
$mysqlDate = date("Y-m-d", strtotime($this->uye_kayit_tarihi));
$criteria->compare('uye_kayit_tarihi', $mysqlDate );
}
*/
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>'uye_id ASC' // sonucları üye numarasına göre sırala
),
'pagination'=>array(
'pageSize'=>5 // sayfada 5 tane sonuç göster
),
));
}
/**
* 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 Uyeler the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function kangrubu()
{
switch($this->kan_grubu){
case "1":
return "A Rh (+)";
break;
case "2":
return "A Rh (-)";
break;
case "3":
return "B Rh (+)";
break;
case "4":
return " B Rh (-)";
break;
case "5":
return "AB Rh (+)";
break;
case "6":
return "AB Rh (-)";
case "7":
return "0 Rh (+)";
break;
case "8":
return "0 Rh (-)";
break;
default:
return "Kan grubu yok";
}
}
public function uyegorevi()
{
switch($this->uye_gorevi)
{
case "1":
return "Üye";
break;
case "2":
return "Başkan";
break;
case "3":
return "Bşk. Yardımcısı";
break;
case "4":
return "Muhasip";
break;
case "5":
return "Sekreter";
break;
case "6":
return "Yedek Üye";
break;
default:
return "Üye Bigisi Yok";
}
}
}
UyeConroller.php
<?php
class UyeController extends Controller
{
public function actionDetayGoster($uye_id)
{
$this->render('detayGoster',array(
'model'=>$this->loadModel($uye_id),
));
}
public function loadModel($uye_id)
{
$criteria=new CDbCriteria;
// $criteria->select='uye_id'; // only select the 'title' column
$criteria->condition='uye_id=:uye_id';
$criteria->params=array(':uye_id'=>$uye_id);
$uyeler=Uyeler::model()->find($criteria);
if($uyeler===null)
throw new CHttpException(404,'Aradığınız Sayfa Bulunamadı.');
return $uyeler;
}
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()
{
if(isset($_POST['Uyeler']))
{
if (isset($_POST['Uyeler'])) // numarasının daha önce kaydelip edilmesigini kontrol ettiren şart.
{
$uyeler = new Uyeler;
$uyeler->attributes = $_POST['Uyeler'];
$kontrol=Uyeler::model()->findAllByAttributes(array('uye_id'=> $uyeler->uye_id));
if ($kontrol) // üye numarası daha önce kaydedilmişse
{
$this->render('mesaj',Yii::app()->user->setFlash('uyeVar', "Hata! Bu üye numarası daha önce başkasına verilmiş."));
}
else { // edilmemişse aşağıdakileri yap
if($uyeler->save(true)) // bilgiler gelmişse veri tabanına kaydet
{
// üye kaydı başarılıysa
header('Refresh:3; url='. $this->createUrl('uye/index')); // üye indexe yönlendir
$this->render('mesaj',Yii::app()->user->setFlash('success', "Üye Başarı ile eklendi."));
}
else // kayitta hata herhangi bir hata oluşursa
{
$this->render('mesaj',Yii::app()->user->setFlash('error', "Hata! Üye Kaydı yapılamadı."));
}
}
}
}
else
{
$uyeler = new Uyeler ; // uyeler modelimizi dahil ettik
$this->render('ekle', array('uyeler'=>$uyeler));
}
}
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');
}
/* public function actionUyenokontrol()
{
$uyeler = new Uyeler ;
$data = Ilceler::model()->findAll('uye_no=:uye_no',
array(':uye_no'=>$_POST['uye_no']));
if (count($data)>0)
{
echo " bu üye daha önce alınmış "..,
}
}
*/
// Uncomment the following methods and override them if needed
/*
public function filters()
{
// return the filter configuration for this controller, e.g.:
return array(
'inlineFilterName',
array(
'class'=>'path.to.FilterClass',
'propertyName'=>'propertyValue',
),
);
}
public function actions()
{
// return external action classes, e.g.:
return array(
'action1'=>'path.to.ActionClass',
'action2'=>array(
'class'=>'path.to.AnotherActionClass',
'propertyName'=>'propertyValue',
),
);
}
*/
}
view file 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' => 'date("d/m/Y", strtotime($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'
, 'viewButtonUrl'=>'Yii::app()->createUrl("/uye/detayGoster", array("uye_id"=>$data["uye_id"]))'
),
),
));
break;
case "kisisel":
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $aramasonucu->search(),
'filter' => $aramasonucu,
'afterAjaxUpdate'=>"function(){jQuery('#tarihegorearama').datepicker({'dateFormat': 'yy-mm-dd','language':'tr'})}", // tarihi seçince çalışmasını ajax fonksiyonu
'columns' => array(
array(
'header'=>'Satır No',
'value'=>'$this->grid->dataProvider->pagination->currentPage*$this->grid->dataProvider->pagination->pageSize + $row+1', // satır numarasını gösteriyor // row is zero based
),
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->kangrubu())',
'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->uyegorevi())',
'filter'=> $uyegorevinegore,
),
array(
'name' => 'uye_kayit_tarihi',
'type' => 'raw',
'value' => 'date("d/m/Y", strtotime($data->uye_kayit_tarihi))',
'filter'=>$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'name'=>'uye_kayit_tarihi',
'language' => 'tr',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat' => 'yy-mm-dd', //save to db format
// 'altFormat' => 'dd-mm-yy', // show to user format
'changeMonth' => 'true', // ay değiştirme
'changeYear' => 'true', // yıl değiştirme
'showOtherMonths'=>true,// Show Other month in jquery
'selectOtherMonths'=>true,// ay seçebilme
//'showButtonPanel'=>true, // altta kapat ve bugün butonlarını oluşturuyor.
'yearRange'=>'1900:2099', // yıl aralığı
),
'htmlOptions'=>array(
'id' => 'tarihegorearama',
'style'=>'width:100px;vertical-align:top'
),
),true), // ifadesini yazmazsak grid içinde görünmüyor
),
array(
'name' => 'uye_durumu',
'type' => 'raw',
'value' => 'CHtml::encode($data->uye_durumu=="1")?("Aktif")<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />"Pasif")',
'filter'=> $uyelikdurumunagore,
),
),
));
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>";
?>