[EXTENSION] Ajax CRUD gii Template

I always thought that the navigation in the view files that the default gii CRUD generator creates is too complex.

This CRUD gii template generates a single Administration page with a CGridView.Update/Create forms and model details view are rendered in a Fancybox Window and deletions go through a confirmation dialog (jUI).The form works with client validation(given that your model validation rules are included in the rules supported by the current Yii client validation).You can switch to Ajax Validation simply by setting the relevant option in CActiveForm instantiation in _ajax_form file,and uncommenting the performAjaxValidation call in ReturnForm action of the controller.See links below

DEMO:SK Yii Test Lab.

Yii Extension Page

Looks nice but the popups animations are a little to much for me.

No problem,go to the fancybox settings and change the animations…


The new crud template is nice. I ran into a problem with it, that took me a minute to figure out. My SQL tables don’t have an id column. I used id"$TableName" (e.g idTest). This breaks the template as it is looking for id(e.g Test.id). A fix I found that works is is to overload the __get() and have it return the correct variable when id is requested. Given my lack of familiarity with Yii is there a way to add a check of the model primaryKey variable?

You mean modify the template code to suit any primary key name?It could be done,but it’s something you’ll have to figure out for yourself.I kept things simple because most of times people name the primary key as id.But thanks for reminding me that maybe I have to stress this out in my extension page,-I don’t mention this anywhere.Why don’t you just rename the primary key as id?

Wishing you success!

I didn’t rename is because i have 20+ table that are set up that way. Which becomes a pain to redo. Thanks for the work on the crud. 8^)

any hope to update this plugin to work with 1.10 ? it gives some js errors, and breaks down the ajax and fancybox functionality

I have it working with that yii version… o_O

Try posting the js errors instead.

The error I am getting is

"variable $js_afterValidate not defined"

or something like that. I solved it inserting


in the _ajax_form.php

Now I am trying to put CJUiDatePicker widget on _ajax_form.php

but it dont work.


I’m new for Yii and I started to develop an application using the Ajax CRUD gii Template, but I’m having a problem. I have some custom validations that are made on the server side. That validations query information in the database and return the response to the page in the JSON’s format. The problem is that the page is not associating the message to the attribute, but it shows a generic message (the error message setted in the <div id=‘error-note’…>). The JSON message’s format returned to the page seems like this: {“Company_name”: [“This name already exists in the database!”]}. How can I fix this and show the correct message?

Best regards!

Israel Boudoux

ajax_create and ajax_update doesn’t work for me

what could possibly happen?

after i ttried to figure it out,

i found in _ajax_form on line 50


should be commented, maybe that variable come from one of your js_plugin, maybe i should find it again

that line should be ‘afterValidate’=>’$.js_afterValidate’,

just a little dot can mess whole control

I could see in your code that you use

url : "<?php echo Yii::app()->request->baseUrl; ?>/someController/returnView"

Why shouldn’t you use

url: "<?php echo $this->createUrl("returnView"); ?>"

instead? (so that the controller name is not hard-coded)

I just revisited my code and saw that the UR for the returnView action in index.php is

  url: "<?php echo '<?php echo '; ?>Yii::app()->request->baseUrl;<?php echo '?>'; ?>/<?php echo $this->class2id($this->modelClass); ?>/returnView",


So I can’t see where the hard coding is.

please help me on ajax update dropdownlist with this template was not working at all, i’ve try on regular yii crud template was running well

on _ajax_form.php

<?php echo $form->dropDownList($model,‘id_propinsi’, array(""=>“Pilih Propinsi”)+CHtml::listData(Refpropinsi::model()->findAll(), ‘id’, ‘nama’),

										array(	'ajax' =&gt; array(



																'update'=&gt;'#Mareal_id_kabupaten', //Mareal[id_kabupaten] Mareal_id_kabupaten

																//'data'=&gt;'js:javascript statement' 

																//leave out the data key to pass all form values through





<?php echo $form->dropDownList($model,‘id_kabupaten’, array());

on controller:

public function actionDynKab(){

		&#036;data=CHtml::listData(Refkabupaten::model()-&gt;findAll('id_propinsi=:id_propinsi',array(':id_propinsi'=&gt;(int) &#036;_POST['Mareal']['id_propinsi'])), 'id', 'nama');

		foreach(&#036;data as &#036;value=&gt;&#036;name)

		{echo CHtml::tag('option', array('value'=&gt;&#036;value),CHtml::encode(&#036;name),true);}


i’ve same problem with you that i cannot update ajax dropDownList, and also the datejui that not work…

3 days to find out :(

this is caused by the ID for the FORM at _ajax_form.php and the ID of FORM at Search form have same name

ex: my ajax_form id Mareal_kabupaten, and at search input ID also Mareal_kabupaten

then when ajax or datejui update the form identify the ID Mareal_kabupaten then ajax or datejui update the first ID found, the first ID was at search FORM, then it’s funny that input form have option :)

solution: try to remark everything about SEARCH form

in my case : i just remark this at index.php


/*Yii::app()->clientScript->registerScript(‘search’, "



return false;


$(’.search-form form’).submit(function(){

&#036;.fn.yiiGridView.update('mareal-grid', {

	data: &#036;(this).serialize()


return false;




<h1>Mareals </h1>

<?php /*?> <p class="left">You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>

or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.</p><?php echo CHtml::link(‘Advanced Search’,’#’,array(‘class’=>‘search-button’)); ?><div class=“search-form” style=“display:none”>

<?php $this->renderPartial(’_search’,array(


)); ?>

</div><!-- search-form --><?php */?>

i just remark all search form and… ALL WORKS… I AM VERRY HAPPY… 3 days working with good result :D

and for you drumaddict who create this ajaxgiicrud… you are the best… made my work eazy with your one page form:)

wow… good looking

And an additional information

you can delete the search.php form and you still can use search function at GRID, then it does not matter if we delete the search form, we can still use grid search text box

any idea if mymodel have a composite primary key?