Sunday, February 16, 2014

CGridView and show detail in CJuiDialog

$this->widget('zii.widgets.grid.CGridView', array(
     .....
     'columns' => array(
         ....
         array(
             'class' => 'CButtonColumn',
             'buttons' => array(
                 'view' => array(
                     'url' => 'url' => 'Yii::app()->createUrl("/path/to/controller/view")',
                     'options' => array(
                         'ajax' => array(
                             'type' => 'POST',
                             'url' => "js:$(this).attr('href')",
                             'update' => '#detail-section',
                         ),
                     ),
  
                 ),    // view button
             ),
         ),
     )
 ));
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
         'id' => 'dlg-detail',
         'options' => array(
             'title' => 'Dialog Box Title',
             'closeOnEscape' => true,
             'autoOpen' => false,
             'model' => false,
             'width' => 550,
             'height' => 450,
         ),
 ));
<div id="detail-section"></div>
 $this->endWidget();

Monday, January 6, 2014

CDetailView with static option value

public static function getUserTypes(){
  return array(
   '10'=> 'admin',
   '5'=> 'Doctor',
                        '4'=> 'Accountant',
                        '3'=> 'Pharmacist', 
                        '2'=> 'Nurse',
                        '1'=> 'Patient',
                        '0'=> 'No User',
  );
 }
 array('name'=>'role', 'value'=>$model->UserTypes[$model->role]),
OR
$services = array('1' => 'Airport Rates', '2' => 'Station Rates', '3' => 'Local Rates');
array(
 'name' => 'services_place',
 'value' => $model->services_place ? $services[$model->services_place]:"",
//      'value' => $model->services_place?$data->getStatus($model->services_place):"",
 
 ),
public function getStatus($services_place)
 {
  $data = array('1' => 'Airport Rates', '2' => 'Station Rates', '3' => 'Local Rates');
  return $data[$services_place];
 }

Wednesday, December 18, 2013

Yii beforeSave method

 function beforeSave() {
            
        if (parent::beforeSave()) {
            if($this->isNewRecord) {
            $this->password=md5($this->password);
             $this->createdate=date("Y-m-d, g:i a");
            }
        else {
            $this->modifydate=date("Y-m-d, g:i a");
          }
        
        }
        return true;
    }

Wednesday, December 4, 2013

yii ajaxLink

echo CHtml::ajaxLink(
  CHtml::image(Yii::app()->request->baseUrl.'/uploads/participants/thumbs/'.$model->picture,
      $model->name, array("style"=>"display:block; margin: 0 auto;height:90px;")),
  Yii::app()->createUrl( 'participants/participantdetails' ),
  array( 
    'type' => 'POST',
    'beforeSend' => "function( request )
                     { }",
    'success' => "function( data )
                  {
                   $('#idrr').html(data);
                  }",
    'data' => array( 'id' => $model->id)
  ),
  array(
    'href' => Yii::app()->createUrl( 'participants/participantdetails' ),
    'class' => 'dffclass'
  )
);

Wednesday, November 20, 2013

yii Custom Function Validation


public function rules()
 {
 array('about_open', 'required'),
 array('about_open', 'my_required'),
}

      public function my_required($attribute_name, $params){
     if($this->about_open==6 && $this->other2==''){
             $this->addError('other2',
                 'Please Pleae fill other field');
     }
     else if($this->about_open==5 && $this->other1==''){
             $this->addError('other1','Please Pleae fill other field');
     }
}


Sunday, November 17, 2013

Yii radioButtonList template....


$arrayvalue = array('1'=>'I heard about it from a friend', '2'=>'I found it on-line', '3'=>'I received an invitation from Tindercapital', '4'=>'I received an invitation from DRIK RVJN', '5'=>'
I received an invitation from another organisation (Please specify) :', '6'=>'
Others (Please specify)');
echo $form->radioButtonList($model,'about_open',$arrayvalue,
array( 'separator'=>' ', 'template'=>"
  • {input}{label}
  • "));

    Friday, November 15, 2013

    yii multiple table with multiple column search

           $criteria = new CDbCriteria;
           $criteria->compare('fullname',$_GET['User']['keyword'],true,'OR'); // $_GET['User']['keyword'] search field name
           $criteria->compare('email',$_GET['User']['keyword'],true,'OR');
           $criteria->compare('phone',$_GET['User']['keyword'],true,'OR');
           $criteria->compare('presentaddress',$_GET['User']['keyword'],true,'OR');
           $criteria->compare('profession',$_GET['User']['keyword'],true,'OR');
           $criteria->with = array('homedistrict0','bloodgroup0','upozila0'); // Relation name
           $criteria->compare('homedistrict0.name',$_GET['User']['keyword'],true,'OR');
           $criteria->compare('upozila0.name',$_GET['User']['keyword'],true,'OR');
           $criteria->compare('bloodgroup0.name',$_GET['User']['keyword'],true,'OR');
           $criteria->together = true;