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.
SK Yii Test Lab,Ajax Crud Demo.
Developed and tested with Yii 1.8,may work with other versions too.
'urlFormat'=>'path', 'showScriptName'=>false,
'modules'=>array( ...... 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'1', // If removed, Gii defaults to localhost only. Edit carefully to taste. 'ipFilters'=>array('127.0.0.1','::1'), 'generatorPaths' => array( 'application.gii' //Ajax Crud template path ), ), ....... )
Your Model class has been generated.
Click Crud Generator
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.
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 14 comments
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.
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.
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.
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
Anyone else with a demo of this extension? The link above is unavailable and I would like to see it in action.
Hi
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.
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!
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
Same for the javascript
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 :)
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.
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. :
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:
Also, when generating the controller, either change the name:
Nice idea though!
and thanks...
Thanks Petro!Nasai kala,efxaristw gia ta kala sou logia.To Yii einai fovero,apla makari kapoia stigmh edw sthn Ellada na to mathoun perissoteroi,giati sthn agora ergasias zhtane olo kati teleiwmena Cake,CodeIgniter klp.
I tested everything in drumaddict's Lab. Excellent extensions (Fobera!)
Looks great!
Veeeeeeryyy nice!! thanks a lot!!!
Leave a comment
Please login to leave your comment.