- Requirements
- Installation
- Basic extension usage
- Widget options
- Extension options
- Create action options
- Delete action options
- Update action options
- View action options
- Tips & Tricks
- Resources
- License
EUpdateDialog is an extension for Yii framework. This extension allows to run controller actions using jQuery UI dialog.
It is used for extending your application to allow easy CRUD (create-read-update-delete) actions or any other action which returns a proper JSON response. Click event can be added to any link element using a jQuery selector, allowing you to extend your application with additional functionality, without sacrificing design.
Extension degrades gracefully, so your application won't lose any functionality if JavaScript is turned off.
Note: I made this extension for the project I'm working on, so like always you are can change it to better suit your needs. If you find this extension useful, please consider a donation. Also please let me know about any bugs or enhancements you find, so that I could have more ideas then working on the next version (new version is good, but I'm still not satisfied with it) :)
Requirements ¶
- Yii 1.1 or above (tested on 1.1.7, 1.1.8)
- jQuery (included in Yii)
- jQuery UI dialog widget (included in Yii)
- jQuery cookie plugin (included in Yii) [optional]
Installation ¶
- actions folder contains controller actions, place it in your application folder (usually
protected
, or in the folder of your choice, just don't forget to updateactions()
method in your controller). - EUpdateDialog folder contains the extension, place it in your applications extensions folder (usually
protected/extensions
). - README.markdown is a readme file in markdown syntax containing this documentation. You can delete this file.
Basic extension usage ¶
Basic extension usage is pretty simple. First make sure your controller has a loadModule()
method and it's something like:
<?php
public function loadModel()
{
if( $this->_model === null )
{
if( isset( $_GET['id'] ) )
$this->_model = ModelName::model()->findByPk( (int) $_GET['id'] );
if( $this->_model === null )
throw new CHttpException( 404, 'The requested page does not exist.' );
}
return $this->_model;
}
?>
Actions automatically sets flash message for additional feedback. If you don't want to use them you will have to remove $controller->setFlash( ... )
calls from you action files. To use flash messages you will need to add following method to your controller:
<?php
public function setFlash( $key, $value, $defaultValue = null )
{
Yii::app()->user->setFlash( $key, $value, $defaultValue );
}
?>
Next change your controllers actions()
method (change the alias if you put them somewhere else):
<?php
public function actions()
{
return array(
'view' => 'application.actions.CreateAction',
);
}
?>
Now make changes to the view file which will use an EUpdateDialog. Add a update-dialog-open-link
class to all the links which need to open in EUpdateDialog. Finally add an extension widget to your view file:
<?php
$this->widget( 'ext.EUpdateDialog.EUpdateDialog' );
?>
That's it, you should be able to use EUpdateDialog extension in your application. However this is the most basic usage of the extension, and you will probably want to customize it to your needs. So keep reading to find out more about customization and other tricks.
Widget options ¶
Here are the available options which you can send to the widget:
dialogOptions is an array containing options for JuiDialog
. You can find all available options at jQuery UI dialog demo page. By default extension only sets autoOpen
and modal
options.
options is an array with options for extension. They should be provided in the option => value
fashion, more on this later.
preload is an array with scripts to preload. This array should contain scripts which are not in the page containing EUpdateDialog extension but is loaded with a page which will be opened in EUpdateDialog. It is used with actions disableScripts
property for extra performance. More on this later.
target is a jQuery selector which will add a click event to the elements for opening EUpdateDialog.
tCategory is a category name for a file which has translations for Yii::t()
method.
Extension options ¶
Extension uses updateDialogOpen()
JavaScript function which initialize the updateDialog
JavaScript object and loads the contents in the dialog.
updateDialog
object properties and methods can be overwritten or extended. Here are the available properties and methods:
csrfToken is a property containing a CSRF token data which is used if your application uses CSRF validation.
csrfTokenName is a property containing the name of CSRF cookie. It's automatically set by the extension.
defaultTitle is a property containing the default title for the dialog. It's used then dialog title is not provided in the link. Defaults to: 'Dialog'. More on adding custom dialog title later.
timeout is a property containing the time (in milliseconds) to wait before running callback. Defaults to: 1000 (one second).
addContent is a method which removes a loader and adds returned contents to the EUpdateDialog.
addLoader is a method which adds the loader. By default it replaces EUpdateDialog contents with 'Loading...'.
callback is a method which runs a callback depending on the status. Currently recognized statuses: 'render', 'success', 'deleted', 'canceled', 'imagedeleted'. Note: if someone knows how to implement something like PHPs $method = 'callback' . $status; if( method_exists( $this, $method ) $this->{$method}();
I would really appreciate if you shared that knowledge. Sharing is caring ;)
canceledCallback is a method which runs if 'canceled' status was received. By default it runs close
method.
cleanContents is a method which removes all EUpdateDialog contents.
close is a method which runs cleanContents
method and closes EUpdateDialog.
defaultCallback is a method which runs when no callback status was recognized. By default it runs close
method.
deletedCallback is a method which runs if 'deleted' status was received. By default it redirects to a redirectToAfterDelete
property value if it's set.
getCsrfToken is a method which sets csrfToken if jQuery cookie plugin and csrfTokenName
property are available.
imageDeletedCallback is a method which runs if 'imagedeleted' status was received. By default it runs close
method. You can ignore this as I added it only because I needed it in my project.
init is a method which initialize the updateDialog
object on the first run. By default it sets the dialog
, defaultWidth
, dialogContent
, csrfToken
properties. It also attaches click
event to all submit buttons (for submitting the form) and all elements with update-dialog-cancel-button
class (for closing dialog) in EUpdateDialog content.
open is an element which opens and load contents for EUpdateDialog. By default it runs cleanContents
method, changes the title
to defaultTitle
if it's not set (title
is set automatically when opening EUpdateDialog), changes the width of the dialog if it's bigger than the window width, opens the dialog, runs the addLoader
and addContent
method.
removeLoader is a method which removes the loader. By default it removes all EUpdateDialog contents.
renderCallback is a method which runs if 'render' status was received. By default it does nothing.
submit is a method which submits the form from EUpdateDialog. By default it gathers all needed form data, runs the addLoader
method, sends the data to a controller action and on success runs the removeLoader
method, updates the EUpdateDialog contents and runs a callback
method with a returned status.
successCallback is a method which runs if 'success' status was received. By default it updates all gridviews with grid-view
class, then updates all listviews with list-view
class and runs close
method.
Create action options ¶
Here are the available options for CreateAction
:
ajaxView has a name of the view to use then action is accessed through AJAX. Defaults to: '_form'.
callback is a callback method in controller for additional processing. It is run after the model is saved and sends the model to a callback method. Defaults to: null. No method is run if callback is null or doesn't exist in the controller.
disableScripts is an array containing the scripts for scriptMap
which should be disabled. By default jquery.js
, jquery.min.js
and jquery-ui.min.js
scripts are disabled. Because $.ajax
doesn't cache scripts, they will always be downloaded. For performance I will suggest to combine all (or most) of JavaScript files into one file which will be included in the page containing EUpdateDialog extension and then in the action disable those scripts. This can be used together with extensions preload
property. (for example WYMeditor don't want to live in the save file as all other scripts, so I preload combined file of WYMeditor script files and disable then disable them in the action).
flashTypePrefix is a prefix for flash message type. Defaults to: ''.
messages is an array containing the messages for the action. By default error
, postRequest
and success
messages are set. Default messages use Yii::t()
for translations.
redirectTo is a redirect URL set by the user. Defaults to: null. If null
user will be redirected to a view
action with a newly created model id
. This property can also be set as an array or a string.
redirectToOnCancel is used to create an url for a link. Useful if you want to use a cancel button/link in your forms.
tCategory is a category name for a file which has translations for Yii::t()
method.
view contains a name of the view to use then action is accessed without AJAX. Defaults to: null. If null
current action id will be used (for example if action is create
the create
view file will be used for rendering).
Note: action allows only POST
requests.
Delete action options ¶
Here are the available options for DeleteAction
:
ajaxView has a name of the view to use then action is accessed through AJAX. Defaults to: '_delete'.
disableScripts is an array containing the scripts for scriptMap
which should be disabled. By default jquery.js
, jquery.min.js
and jquery-ui.min.js
scripts are disabled. Because $.ajax
doesn't cache scripts, they will always be downloaded. For performance I will suggest to combine all (or most) of JavaScript files into one file which will be included in the page containing EUpdateDialog extension and then in the action disable those scripts. This can be used together with extensions preload
property. (for example WYMeditor don't want to live in the save file as all other scripts, so I preload combined file of WYMeditor script files and disable then disable them in the action).
flashTypePrefix is a prefix for flash message type. Defaults to: ''.
redirectTo is a redirect URL set by the user. Defaults to: null. If null
user will be redirected to a view
action with an updated model id
. This property can also be set as an array or a string.
redirectToAfterDelete is used to as a redirect URL after successful deletion. Defaults to: array( 'admin' )
.
tCategory is a category name for a file which has translations for Yii::t()
method.
view has a name of the view to use then action is accessed without AJAX. Defaults to: null. If null
current action id will be used (for example if action is delete
the delete
view file will be used for rendering).
Note: action allows only POST
requests.
Update action options ¶
Here are the available options for UpdateAction
:
ajaxView has a name of the view to use then action is accessed through AJAX. Defaults to: '_form'.
callback is a callback method in controller for additional processing. It is run after the model is saved and sends the model to a callback method. Defaults to: null. No method is run if callback is null or doesn't exist in the controller.
disableScripts is an array containing the scripts for scriptMap
which should be disabled. By default jquery.js
, jquery.min.js
and jquery-ui.min.js
scripts are disabled. Because $.ajax
doesn't cache scripts, they will always be downloaded. For performance I will suggest to combine all (or most) of JavaScript files into one file which will be included in the page containing EUpdateDialog extension and then in the action disable those scripts. This can be used together with extensions preload
property. (for example WYMeditor don't want to live in the save file as all other scripts, so I preload combined file of WYMeditor script files and disable then disable them in the action).
flashTypePrefix is a prefix for flash message type. Defaults to: ''.
messages is an array containing the messages for the action. By default error
, postRequest
and success
messages are set. Default messages use Yii::t()
for translations.
redirectTo is a redirect URL set by the user. Defaults to: null. If null
user will be redirected to a view
action with an updated model id
. This property can also be set as an array or a string.
tCategory is a category name for a file which has translations for Yii::t()
method.
view has a name of the view to use then action is accessed without AJAX. Defaults to: null. If null
current action id will be used (for example if action is update
the update
view file will be used for rendering).
Note: action allows only POST
requests.
View action options ¶
ajaxView has a name of the view to use then action is accessed through AJAX. Defaults to: '_view'.
disableScripts is an array containing the scripts for scriptMap
which should be disabled. By default jquery.js
, jquery.min.js
and jquery-ui.min.js
scripts are disabled. Because $.ajax
doesn't cache scripts, they will always be downloaded. For performance I will suggest to combine all (or most) of JavaScript files into one file which will be included in the page containing EUpdateDialog extension and then in the action disable those scripts. This can be used together with extensions preload
property. (for example WYMeditor don't want to live in the save file as all other scripts, so I preload combined file of WYMeditor script files and disable then disable them in the action).
messages is an array containing the messages for the action. By default postRequest
messages are set. Default messages use Yii::t()
for translations.
tCategory is a category name for a file which has translations for Yii::t()
method.
view has a name of the view to use then action is accessed without AJAX. Defaults to: null. If null
current action id will be used (for example if action is view
the view
view file will be used for rendering).
Note: action allows GET
requests which have ajax
parameter. This request will run ajaxUpdate
method which will load the model and render non AJAX view without processing JavaScript (I use it in view pages to reload contents, but watch out for extensions which use jQuery bind
).
Tips & Tricks ¶
Here are a few tips & tricks (they are mostly taken from the project I'm working on so update to your own needs).
EUpdateDialog links ¶
To open EUpdateDialog when clicking on the link; add custom title:
<?php
echo CHtml::link( 'Create', array( 'create' ),
array(
'class' => 'update-dialog-open-link',
'data-update-dialog-title' => Yii::t( 'app', 'Create a new mix' ),
));
?>
Add customized EUpdateDialog widget ¶
This code will add an EUpdateDialog with custom successCallback, deletedCallback methods (write them as "js:function(){ // your code }"
, don't use ;
at the end!). This will also preload a wymeditor.js
file:
<?php
$widgetUpdate = "js:function(){}";
$this->widget( 'ext.EUpdateDialog.EUpdateDialog', array(
'options' => array(
'successCallback' => $widgetUpdate,
'deletedCallback' => $widgetUpdate,
),
'preload' => array( Yii::app()->request->baseUrl . '/js/wymeditor.js' ),
));
?>
GridView widget ¶
To make gridview widget default buttons use EUpdateDialog change your columns
in a widget to look something like this:
<?php
$this->widget( 'zii.widgets.grid.CGridView', array(
...
'columns' => array(
...
array(
'class' => 'CButtonColumn',
'buttons' => array(
// Delete button
'delete' => array(
'click' => 'updateDialogOpen',
'url' => 'Yii::app()->createUrl(
"/admin/mix/delete",
array( "id" => $data->primaryKey ) )',
'options' => array(
'data-update-dialog-title' => Yii::t( 'app', 'Delete confirmation' ),
),
),
// Update button
'update' => array(
'click' => 'updateDialogOpen',
'options' => array(
'data-update-dialog-title' => Yii::t( 'app', 'Update mix' ),
),
),
// View button
'view' => array(
'click' => 'updateDialogOpen',
'options' => array(
'data-update-dialog-title' => Yii::t( 'app', 'Preview mix' ),
),
),
),
),
),
));
?>
Add cancel link in your form ¶
To add cancel link (returns to a model view or some other page normally, closes EUpdateDialog then using extension) in forms use this code:
<?php
echo CHtml::link( 'Cancel', $cancelUrl, array(
'class' => 'update-dialog-cancel-button' ) );
?>
Advanced controller action configuration ¶
This is the code for configured action. This will run addFeedItem
method in controller after successfully saving the model. It will also disable the scripts in the form (guilty as charged, all extensions are made by me :D ) and replace success
message:
<?php
public function actions()
{
return array(
'create' => array(
'class' => 'application.actions.CreateAction',
'callback' => 'addFeedItem',
'disableScripts' => array(
'jquery.wymeditor.js',
'jquery.wymeditor.fullscreen.js',
'jquery-ui-timepicker-addon.js',
'chosen.jquery.min.js',
),
'messages' => array(
'success' => 'Mix successfully created',
),
),
);
}
?>
Delete view ¶
This is very important: you must have a delete view which has to containing a form with two submit buttons named deleteConfirmed
(to confirm deletion) and deleteCanceled
(to cancel deletion).
<?php
echo CHtml::submitButton( 'Yes', array( 'name' => 'deleteConfirmed' ) );
echo CHtml::submitButton( 'No', array( 'name' => 'deleteCanceled' ) );
?>
Resources ¶
- Wiki article
- Forum topic - (questions, bugs, etc.)
- GitHub repository
- If you find this extension useful, please consider a donation
License ¶
The extension is licensed under MIT license.
Problem with delete button
I use this code
'class'=>'CButtonColumn', 'template'=>'{delete}{update}{up}', 'deleteButtonUrl' => 'Yii::app()->createUrl("/testTable/delete" , array( "id" => $data->primaryKey ) )', 'deleteConfirmation'=>true, 'buttons' => array( 'delete' => array( 'click' => 'updateDialogDelete', 'options'=>array('class'=>'dialog') ),
but don't work. If i use class update the dialog open
@ciro.mar
Try changing 'deleteConfirmation' to false.
It shouldn't be using it because 'click' property is set, but you never know.
I would also suggest getting FireBug add-on for your browser, that way with NET panel you can track your traffic (if you get a red entry most of the time it's a problem with link).
Name of class
The problem was the name of the class.
When I read your guide I thought the name of the class could be one of these values. 'create' or 'dialogue' or 'update'. Entering class instead "update-dialog-create" it's works.
There is still a problem but I think it is better to discuss on the forum ..
var csrfToken = null;
dude, thank you for the zip file. it is really helpful.
now I have one note,
I went to the chat room at yiiframework.com/chat and there was a great person whose name is ciss_
s/he helped me figure out one issue about this tutorial.
one should add the following to the main config file:
'request' => array('enableCsrfValidation' => true),
otherwise the action name would not be sent properly ,
I mean instead of being sent as confDelete, it becomes confDeletenull,
that is due to the line 5 in the file eUpdateDialog.js
var csrfToken = null;
so line 10 would add null to the action name.
a fix to this issue maybe changing line 5 into
var csrfToken = '';
or emphasizing that enabling CSRF validation is mandatory for this tutorial to work properly.
another issue
the delete click function does not accept to be overridden. I mean it keeps using its original function. I figure it that is due to the code lines 235-253 in CButtonColumn.php
when I remove this code the override works.
however I don't think removing code from core files is a good policy.
I don't know how does it work for you.
I made another button with a different name and it works fine.
but with the button "delete" it never work without removing those lines.
@aladdin
Extensions JavaScript is still a little messed up, so thanks for letting me know about csrf problem. On my tests with and without csrf validation everything was fine so I probably missed that.
Following the Yii docs http://www.yiiframework.com/doc/api/1.1/CButtonColumn#deleteConfirmation-detail
the confirmation message to be displayed when delete button is clicked. By setting this property to be false, no confirmation message will be displayed. This property is used only if $this->buttons['delete']['click'] is not set.
As you set ['delete']['click'] inside gridview it shouldn't use default function for delete. I look into that later, maybe I will be able to make mine not to work.
As this extension is getting a little popular, I will try to find some free time to update this by today or tomorrow.
javascript validation on fields before the dialog open
How to put javascript check on certain fields before dialog got open ? I have tried like the one below it s not working with the class added as "update-dialog-create". Alert message is pop out and but still dialog opens after that . Any help ?
echo CHtml::link('Add Trip Details', '#', array( // 'class'=>'update-dialog-create', 'onclick'=>'js:validateForm();return false;', ) );
@traceshankar
Can you explain in more details what exactly it is you want to do?
You can use the forum topic for that forum topic
How to pass value to popup dialog in create mode from filter
<?php echo CHtml::link( 'Add Region', '#', array ( 'onclick' => 'var url = "' . $this->createUrl('create') . '"; var country_id = $("select[name*=country_id]").val(); url += "?country_id=" + country_id; updateDialogActionBase(url, "Add Region"); return false;', ) ); .... 'columns'=>array( array( 'name' => 'country_id', 'header' => 'Country', 'type' => 'raw', 'value' => '$data->country->name', 'filter' => $this->getCountryFilter(), ), ... ?>
a weird problem !
Is it possible to use CAutoComplete widget in create/update dialog? actually I have used this widget in my dialog forms and it's somehow working, means it inserts new rows in DB, but the problem is after submitting the form -by pressing create button- dialog doesn't close!
I have checked this process via Firebug console, and below error came up after pressing create button:
invalid label {"status":"success","content":"ModelName successfully created"}
so, how can I fix this problem?! what is wrong with using autoComplete and dialog in same window?!
@alireza.ghasabeh
I think the problem is because you have 'invalid label' in your respospense. You need a valid JSON data to be returned, so it corrupts your data, you should check your controller or autocomplete code to see why you get that string.
a weird problem #2
of course that's the problem! i wondered if anyone knows what it is because and how to solve it or not !
and if it helps, both dialog updater and auto complete widget works well when i use them separately.
same problem with 'alireza.ghasabeh'
I have the same problem when using autoComplete widget and dialog updater together, and it seems i'm not the only one having this problem. isn't there any solutions for this problem?! there must be something to try at least!
CSRF couldn't been validated
as long as
enableCookieValidation is set to true
'request' => array(
'class' => 'CHttpRequest', 'enableCookieValidation' => false, 'enableCsrfValidation' => true,
),
Any solution for this?
how to use CHtml::button
Took me a bit to figure this out, but the following will create a button that works with EUpdateDialog:
echo CHtml::button('Click me', array( 'type'=>'submit', 'href' => Yii::app()->createUrl('myModule/manage/create', array('user_id' => $model->user_id)), 'class' => 'update-dialog-open-link', 'data-update-dialog-title' => Yii::t('Pop-up title goes here' ), ));
Not working
the dialog box open but just display 'loading'.. actually im calling crud form from the other model than the gridview one.. this is my parent view..
<?php $this->breadcrumbs=array( 'SPM', $model->idPemohon->nama, ); $this->menu=array( array('label'=>'1. Maklumat Peribadi', 'url'=>array('/pemohon/view', 'id' => $model->id)), array('label'=>'3. Maklumat Pengajian', 'url'=>array('/pemohon/pengajian', 'id' => $model->id)), array('label'=>'4. Maklumat Ko-kurikulum', 'url'=>array('/kokurikulum/index', 'id' => $model->id)), ); ?> <h2>Maklumat SPM : <?php echo $model->idPemohon->nama; ?></h2> <?php $this->widget('zii.widgets.CDetailView', array( 'data'=>$model, 'attributes'=>array( // 'id', 'idPemohon.nama', // 'id_sekolah', 'sekolah', 'tahun', ), )); ?> <?php /* $widgetUpdate = "js:function(){}"; $this->widget( 'ext.EUpdateDialog.EUpdateDialog', array( 'options' => array( 'successCallback' => $widgetUpdate, 'deletedCallback' => $widgetUpdate, ), 'preload' => array( Yii::app()->request->baseUrl . '/js/wymeditor.js' ), )); */ $this->widget( 'ext.EUpdateDialog.EUpdateDialog' ); ?> <?php $config = array(); $dataProvider = new CArrayDataProvider($rawData=$model->spmSubjek, $config); $this->widget( 'zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider ,'template'=>'{items}', 'columns' => array( array( 'header'=>'Bil', 'value'=>'$row+1', // row is zero based ), 'subjek.descr:raw:Subjek', array( // display 'create_time' using an expression 'name'=>'Markah', 'value'=>'$model->tahun > 2008? $data->gred->gred_09 : $data->gred->gred_09', ), array( 'class' => 'CButtonColumn', 'buttons' => array( // Delete button 'delete' => array( 'click' => 'updateDialogOpen', 'url' => 'Yii::app()->createUrl( "/spmsubjek/delete", array( "id" => $data->id ) )', 'options' => array( 'data-update-dialog-title' => Yii::t( 'app', 'Delete' ), ), ), // Update button 'update' => array( 'click' => 'updateDialogOpen', 'options' => array( 'data-update-dialog-title' => Yii::t( 'app', 'Update' ), ), ), // View button 'view' => array( 'click' => 'updateDialogOpen', 'options' => array( 'data-update-dialog-title' => Yii::t( 'app', 'View' ), ), ), ), ), ), )); ?> <?php echo CHtml::link( 'Tambah Subjek', array( '//spmsubjek/create' ), array( 'class' => 'update-dialog-open-link', 'data-update-dialog-title' => Yii::t( 'app', 'Tambah Subjek' ), )); ?>
what display in the grid was the child model of the view and i put all the extension setting in the child controller not the parent. This is my controller:
<?php class SpmSubjekController extends Controller { public $layout='//layouts/column2'; private $_model; public function filters() { return array( 'accessControl', ); } public function accessRules() { return array( array('allow', 'actions'=>array('index','view','setFlash','actions'), 'users'=>array('*'), ), array('allow', 'actions'=>array('create','update'), 'users'=>array('@'), ), array('allow', 'actions'=>array('admin','delete'), 'users'=>array('admin'), ), array('deny', 'users'=>array('*'), ), ); } public function actionView() { $this->render('view',array( 'model'=>$this->loadModel(), )); } public function actionCreate() { $model=new SpmSubjek; if(isset($_POST['SpmSubjek'])) { $model->attributes=$_POST['SpmSubjek']; if($model->save()) { if (Yii::app()->request->isAjaxRequest) { echo CJSON::encode(array( 'status'=>'success', 'content'=>"<div id='saveconfirm'>Data telah disimpan!</div>", 'option'=>CHtml::tag('option',array ( 'value'=>$model->id, 'selected'=>true), CHtml::encode($model->id),true) )); exit; } else $this->redirect(array('view','id'=>$model->id)); } } if (Yii::app()->request->isAjaxRequest) { echo CJSON::encode(array( 'status'=>'failure', 'content'=>$this->renderPartial('_form', array('model'=>$model), true) )); exit; } else $this->render('create',array( 'model'=>$model, )); } public function actionUpdate() { $model=$this->loadModel(); $this->performAjaxValidation($model); if(isset($_POST['SpmSubjek'])) { $model->attributes=$_POST['SpmSubjek']; if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('update',array( 'model'=>$model, )); } public function actionDelete() { if(Yii::app()->request->isPostRequest) { $this->loadModel()->delete(); if(!isset($_GET['ajax'])) $this->redirect(array('index')); } else throw new CHttpException(400, Yii::t('app', 'Invalid request. Please do not repeat this request again.')); } public function actionIndex() { $dataProvider=new CActiveDataProvider('SpmSubjek'); $this->render('index',array( 'dataProvider'=>$dataProvider, )); } public function actionAdmin() { $model=new SpmSubjek('search'); if(isset($_GET['SpmSubjek'])) $model->attributes=$_GET['SpmSubjek']; $this->render('admin',array( 'model'=>$model, )); } public function loadModel() { if($this->_model===null) { if(isset($_GET['id'])) $this->_model=SpmSubjek::model()->findbyPk($_GET['id']); if($this->_model===null) throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.')); } return $this->_model; } protected function performAjaxValidation($model) { if(isset($_POST['ajax']) && $_POST['ajax']==='spm-subjek-form') { echo CActiveForm::validate($model); Yii::app()->end(); } } public function setFlash( $key, $value, $defaultValue = null ) { Yii::app()->user->setFlash( $key, $value, $defaultValue ); } public function actions() { return array( 'view' => 'application.actions.CreateAction', ); } }
was this differential make my code didnt working or sumthing else..? pls..
Tweak to support Dialog buttons
I had a need of supporting dialog buttons with this great extension. I could have set the buttons with the extension options, but (AFAIK) there was no way to change it if you had multiple dialog links that needed different buttons (delete vs update). So I made this.
http://pastebin.com/eW6D6w5k
This diff will allow you to set
'data-update-dialog-type' => 'TYPE',
as a CButtonColumn option (wheredata-update-dialog-title
is set). I have not tested it outside grid view button column, but it should work with any link as long as you adddata-update-dialog-type
as an attribute via htmlOptions or whatever.Currently supports 3 flavors:
'delete'
will add two buttons, one that submits the form, one that closes the dialog.undefined
(leaving option out) or'self'
will not add buttons, relying on the rendered form for the submit buttonsdefault
: anything else will add one Submit button which will submit the form.You can add functionality to this fairly easily by tweaking the buttonSet function.
thanks
nice. thanks.
Need for default attributes on create
Hi, I need to set some related attributes on create method so I added the following :
Create action:
/** * @var array attributes to be passed to the model after create */ public $attributes = array();
Init method:
//Initialize attributes via get if (isset($_GET['attributes'])) { $this->attributes = $_GET['attributes']; }
run method:
// Create the model $model = new $modelClass(); //Set configured attributes $model->attributes = $this->attributes;
Create url array:
...array('/controller/create', 'attributes'=>array(...attributes to be initialized...))...
Any tips for better practices?
Yii 1.1.16 (with jQuery 1.9)
Updating to Yii 1.1.16 will break this extension because of many deprecated jQuery .live() events in its code.
So, this is how to replace .live() with .on() in extension's code:
EUpdateDialog.php: line 101, 102, 103
$cs->registerScript('eupdatedialog', " jQuery( '{$this->target}' ).on( 'click', updateDialogOpen );", CClientScript::POS_END);
assets/EUpdateDialog.js: line 185, 186
~~~
[javascript]
$('.update-dialog-content')
.on('click', 'input[type=submit]', function (e) {
[**assets/EUpdateDialog.js: line 195, 196**](https://github.com/ifdattic/EUpdateDialog/blob/master/EUpdateDialog/assets/EUpdateDialog.js#L195 "go to GitHub")
[javascript]
$('.update-dialog-content')
.on('click', '.update-dialog-cancel-button', function (e) {
Yes it is!!
Reply to #19220 comment
Thanks!
Can you send the PR on GitHub with these changes?
As I don't work with Yii or actively support extensions anymore this would provide the changes to everyone.
Reply to #19225 comment
Hi Ifdattic! I've just push changes and create a PR!
Thanks
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.