Extending CJuiDialog

You are viewing revision #2 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.

« previous (#1)next (#5) »

Sometimes you have CJuiDialog with different content but same buttons (or width, height). If you don't want to repeat yourself this is a great solution:

Create:

> extensions/dialog/start.php

In start.php write:

Yii::import('zii.widgets.jui.CJuiDialog');
class Start extends CJuiDialog
{
         
        public function init()
        { 
                
                $options=$this->options;
                
                $options['buttons']=array(
                     'Save'=>'js:function(){alert("alert one");}',      
                     'Cancel'=>'js:function(){alert("alrt two");}', 
                );
           
                $this->options=$options;
                parent::init();

         }

}         

Somewhere (in views) create:

$this->beginWidget('ext.dialog.start', array(
                             'id'=>'dialog',
                              'options'=>array(
                                           'title'=>'Title',
                                           'autoOpen'=>false,
                                           'modal'=>true,
                                           'width'=>320,
                                           'resizable'=>false,
                                           'height'=>'auto',
                                           )
                        ));                                     
                                                                        
  
 $this->renderPartial('view_file');
 
 $this->endWidget(); 

And that's it. You will have buttons Save and Cancel everytime.

1 2
2 followers
Viewed: 18 432 times
Version: Unknown (update)
Category: How-tos
Written by: dstudio
Last updated by: Maurizio Domba Cerin
Created on: Jul 25, 2012
Last updated: 11 years ago
Update Article

Revisions

View all history

Related Articles