Yii 1.1: ajaxcrudgiitemplate

Gii CRUD template for Single Page Ajax Administration.


You may want to check first the latest behavior driven version of this extension,ajax-crud-behavior.This is an outdated extension.


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.


Developed and tested with Yii 1.8,may work with other versions too.


  • Hide index.php from your requests,if you have'nt done so yet.You can find detailed instructions on how to do this here.(Paragraph 6) Also,in urlManager configuration in config/main.php file set
  • Unzip the downloaded file.
  • Copy the gii folder to your application's protected folder.
  • Copy the js_plugins folder to the root folder of your application,(same level as protected).
  • In config/main.php file,in gii configuration, add the path of your gii folder like so:
            // If removed, Gii defaults to localhost only. Edit carefully to taste.
                        'generatorPaths' => array(
                        'application.gii'  //Ajax Crud template path


  • Create the table for your model in the database.Use id as your primary key column name.
  • Click Model Generator.Type the table name in the Table Name field.
  • Preview if you want,and then Generate.
  • Your Model class has been generated.

  • Click Crud Generator

  • In the Model Class field type the name of the class that was generated in the previous step.
  • Click Code template and select ajax_crud,if it's not already selected.
  • Preview if you want,and then Generate.

This is it.Navigate to the Administration page:go to [application root]/[controller ID]/.You should see the administration page and you are ready to perform CRUD operations on the model.


Spiros "drumaddict" Kabasakalis,November 5th 2011.


  • 1.3.December 11th 2011.

Form submission is now handled by jQuery Form Plugin (see resources). This has the advantage that you can include a file field in your form,and it will be submitted without a page refresh,although this is not technically ajax,(as the XHR object cannot handle this task). For more information see online jQuery Form Plugin documentation.

'afterAjaxUpdate' callback of CGridView now does not duplicate the code declared in the script tag. It just calls a js function declared in the script tag so unnecesssary code repetition has been eliminated.

Fancybox 2 is now used for the form rendering.Please see the licence for fancybox2 online.(resources).

  • 1.2.Deprecated

  • 1.1.November 9th 2011.

Made some changes so that the application root folder is not hardcoded in URLs,in generated views and controller. Now generated code is valid in local and production enviroment as well,without the need to manually change the URLs. Thanks to Asgaroth for pointing this out to me. Cheers!

Total 17 comments

#16221 report it
Selim at 2014/01/31 12:20am
Delete is not working

I really love this extension.

But delete is not working it says "Error 404:The system is unable to find the requested action "view"."

Also I need Batch delete .

Could you please help me out ?

#15576 report it
Rajith R at 2013/11/22 11:59pm

@drumaddict - custom Validation rules not working Custom Validation rules and validation like 'unique'are not working . What to do?

#15575 report it
drumaddict at 2013/11/22 01:21pm
@morteza toloo

I have not considered modules in this extension,you are on your own with this.I suggest you take a look at ajax-crud-behavior ,a behavior driven version of this extension.I cannot guarantee that it will work in modules though,I did not consider modules because I never use them.

#15574 report it
morteza toloo at 2013/11/22 11:33am
Incorrect links at module

When using at a module for example admin module, links would be incorrect and view, update, delete wouldn't work. the problem is that generating URL doesn't consider the module name:

url: "<?php echo Yii::app()->request->baseUrl;?>/CONTROLLER/returnForm",
#11529 report it
pingala at 2013/01/18 10:23am
Taking the form out of the fancybox in the main body

I like this extension even though it could do better with a little bit more of documentation. For instance I would like to get rid of the fancybox and instead having the form (for editing/view/etc.) appearing embedded in the grid page at the bottom or top of the grid .. where should I go to modify the plugin to do this?

I guess in /views/mytablewhatever/index.php where it says $('.fan_update') in the related section UPDATE or VIEW or CREATE on the success action... but the semantic there look bit odd to me (not much familiar with Jquery though)

any help appreciated

#7731 report it
drumaddict at 2012/04/13 02:23am

You are right,I thought of that.Do you know how to do that?'Cause I don't have time to work this out.Will appreciate some contribution....UPDATE. I recently figured out how to add batch(mass) delete functionality in CGridView with a checkbox column.I am using it right now in my CMS,when I find time,I might update this extension to take advantage of mass deletes.

#7730 report it
saegeek at 2012/04/13 01:12am
it would be nice...

Ajax looks really fast, much thanks ! But When we have to delete 100 records it takes very long time. You should add a column with checkboxes for batch deletion.

#6681 report it
ianaré at 2012/01/27 06:40pm
primary keys

Hi, thanks for this extension.

Couple problems I noticed within a few minutes of install:

In the generator, you have 'id' hard coded as the primary key for the model. You should change this to getPrimaryKey().

This happens in 'index.php' and '_ajax_form.php'

You'll still have a problem with compound PK models though. I have some models that use these, I will look into a possible fix. But the above is a quick fix that you could easily do.


The indentation is very different from the normal Yii files. In a plain text editor, it makes your code very hard to read.

#5852 report it
saebaryo at 2011/11/20 06:11pm
"fancybox" can't be displayed

i always success generate code, but when my table name using underscore "_" like "test_one", the modal window "fancybox" can't be displayed, that because generate code produce code "test-one-....". so i replace all "test-one-..." with the "testOne-..." by modif template code

// just with
#5749 report it
Gustavo at 2011/11/09 08:08am
Changes proposed


I agree with Asgaroth, I was actually just changing your extension to made all these changes proposed by him. As soon as I have something done, I'll let you know and post it in the extensions forum topic.

Anyway, this is a great extension. Thanks for sharing your work.

PS. You should provide a link for the forum topic here, in the extension page.

#5748 report it
drumaddict at 2011/11/09 05:20am
@Asgaroth Apologies!

If someone does the code generation on the server there's no problem,but -yeah most of us develop locally,so the generator will hard code the local application root url.Will try to fix it as soon as possible,when I find free time.Thanks for your comments!

#5744 report it
Asgaroth at 2011/11/08 06:13pm

thanks for your response:

I was talking about the ajax_admin.php view generated files.

in the CGridView columns configuration for CButtonColumns generates code that looks like

'imageUrl' => 'myapp/css/image..
//instead of
'imageUrl' => Yii::app()->baseUrl.'/css/image..

Same for the javascript

                type: "POST",
                url: "/myapp/bebe/returnView",
//instead of 
                type: "POST",
                url: '.Yii::app()->baseUrl.'"/bebe/returnView",

Any way, you should not have that much javascript in a view. and im prretty sure the javascript is almost the same, even if not, you can always create a plugin and funcions that receive the urls, because the only possible change from a model to another is the URL call. which can, in the end, be just the parameter of a javascript function in a external javascript file. reusing code, and archieving organization.

Its just my opinion, I just like things as organised as possible :)

#5743 report it
drumaddict at 2011/11/08 05:11pm

Hi Asgaroth, - About the duplicated javascript.It's not the same if you pay close attention-almost the same.The javascript for the create operation is not included in afterAjaxUpdate. Declaring a javascript object would make sense only if I used the same js code many times. - About the controller name,I don't think it's a big deal.The default CRUD generator uses IndexController for listing the model rows,and AdminController for the page with the CGridView,so I just appended an ajax suffix to remind people that this replaces the default Admincontroller.Changing the controller name is so simple and anyone with a basic Yii knowledge can do it,so no big deal,in my opinion. Thanks for appreciating my extension.

#5742 report it
Asgaroth at 2011/11/08 04:14pm

Very nice idea, and I appreciate you shared this with us.

however there are a couple of basic errors you could fix to improve this extension. firts of all you "hardcode" (when generating) the app base URL, making the generated code unportable across different servers. :

//use :
//instead of

Secondly you ajax_admin views have A LOT of javascript, and its also duplicated, in the afterAjaxUpdate CGridView attribute and then again after that.

Try creating global javascript objects, or append a javascript object to the jQuery object so that you can do:

'afterAjaxUpdate' => 'js:AjaxCrud.gridAfterAjaxUpdate'
//Instead of
'afterAjaxUpdate' => 'js:A HELL BUNCH OF JAVASCRIPT CODE'

Also, when generating the controller, either change the name:

public function actionAjax_Admin()
public function actionIndex()
//Or override the class attribute $defaultAction
public $defaultAction = "ajax_admin";
// so that the generated code works easily without manual modification.

Nice idea though!

and thanks...

#5726 report it
petros at 2011/11/07 04:34am

I tested everything in drumaddict's Lab. Excellent extensions (Fobera!)

#5720 report it
wisp at 2011/11/06 05:37pm

Looks great!

#5709 report it
betelgeuse at 2011/11/05 11:25am

Veeeeeeryyy nice!! thanks a lot!!!

Leave a comment

Please to leave your comment.

Create extension