Social Icons


Monday, May 27, 2013

Ajax SubmitButton Yii

  1. <?php echo CHtml::ajaxSubmitButton( 'Send',
  2.                                         CHtml::normalizeUrl(array('site/ajaxIndexSubmit')),
  3.                                         array(
  4.                                         'error'=>'js:function(){
  5.                                             alert('error');
  6.                                         }',
  7.                                         'beforeSend'=>'js:function(){
  8.                                             alert('beforeSend');
  9.                                         }',
  10.                                         'success'=>'js:function(data){
  11.                                             alert('success, data from server: '+data);
  12.                                         }',
  13.                                         'complete'=>'js:function(){
  14.                                             alert('complete');
  15.                                         }',
  16.                                         //'update'=>'#where_to_put_the_response',
  17.                                         )
  18.                                     );
  19.     ?>

Thursday, May 23, 2013

cgridview value from functions

 In CGridView,  a column where  want to modify the value with a getter function from a model I have loaded. 
view Cgridview


in model function subjectFormated()

public static function subjectFormated($model){
       ////will get model->subject 
.....your code...................

Wednesday, May 22, 2013

Create custom button with AJAX function in CGridView

First we need to create the required action in our controller, we will call it simply ‘status’.  To begin we add it in our controller rules ‘actions’ array:
      'actions'=>array('view''update', 'delete', 'status')),

Next we need to create an action for setting our record status:

public function actionStatus($id)

    $model = MyModel::model()->findByPk($id);  // use whatever the correct class name is
    $model->status = ($model->status ==1 ? 1 : 0);
    return true;

Now we are ready to create our custom button.  If you look at a standard Yii generated cGridview, toward the bottom you will see the following:
This we need to extend to include both our standard buttons plus our new custom button, making use of ‘ajax’ in the ‘options’ array:
     'template' => '{view}{update}{status}{delete//include the standard buttons plus the new status button
         'status' => array

             'imageUrl'=>'images/icn/status.png'// make sure you have an image
             'url'=>'Yii::app()->createUrl("mycontroller/status", array("id"=>$data->id))',
             'options' => array(

 'confirm'=>'Are you want to change status?',
'ajax' => array('type' => 'get', 'url'=>'js:$(this).attr("href")', 'success' => 'js:function(data) { $.fn.yiiGridView.update("my-grid")}')

Important things to note above:
  1. You need an image for your new button, I have used ‘images/icn/status.png’
  2. For the yiiGridView update() function, make sure that you enter the correct ID for your grid

further Reference