This extension provides giix templates for ajax CRUD code generation of a MANY_MANY Model relationship,between Category-like and Product-like Models. The Category-like model is given a nestedset Behavior and administered with jstree plugin. The Product-like model is administered with either a CGridView or a CListView. Clicking on the category nodes of the tree will filter the product records in a CGridView(or CListView). Frontend views are also provided,with only read (view) operation. The forms are rendered in a pop up window (fancybox) and the submission is an ajax process.However because the jquery form plugin is used (see resources) ,it is possible to include a file field and submit the form without a page refresh.This is not ajax though,as the XHR object cannot do this.A technique involving an iframe is used.For more info see jquery form plugin documentation.
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 js_plugins folder to the root folder of your application,(same level as protected).
- Copy the img folder folder to the root folder of your application,(same level as protected).
- Copy the many_many.css file to your application's css folder,(or create the css folder if it does'nt exist).
- Copy the fileimagebehavior,giix-components,giix-core,image,nestedBehavior folders to the extensions folder of your application. Note:If you already have giix installed you only need to copy the templates found in extensions\giix-core\giixCrud\templates and extensions\giix-core\giixModel\templates.(many_many_category,many_many_many_product folders).
- In your config/main.php file include in the import section:
'import'=>array( // ... **other imports**... 'ext.giix-components.*', // giix components 'ext.fileimagebehavior.*' // ... **other imports**.. ) ~~~ - In config/main.php file,in gii configuration, add the path of your giix-core folder like so:
'modules'=>array( ...... 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'[YOUR PASSWORD]', 'ipFilters'=>array('127.0.0.1','::1'),// If removed, Gii defaults to localhost only. 'generatorPaths' => array( 'ext.giix-core', // giix generators ), ), ....... )
##Usage - Design the database schema of the MANY_MANY relationship and create the tables in your database. A sample schema is provided in many_many.sql file. You will need three tables,two for the related models and one pivot table. You can use any name for the tables as long as they are simple:one word,all letters lowercase. For convenience's sake let's call one table product and the other category. In this case the pivot table is usually named product_category. Please read the comments in many_many.sql file to see which table columns are required for this extension to work. The category table will generate a model with nested behavior and will be administered with a tree (jstree plugin) in admin view files. The product table will generate a model administered with either a CGridView or CListView. Clicking on the category nodes of the tree will filter the product records in CGridView(or CListView). - With the tables created ,you can proceed to code generation with gii. Navigate to gii [application root]/gii. - Click GiixModel Generator.Type the product table name in the Table Name field. - Important!Accept the model class name suggested by gii, don't try any other fancy names like MyProduct,My_Product etc.Just keep Product. This applies to the other two tables as well. - Click Code Template and choose the many_many_product template. - Preview if you want,and then Generate. - Your Product model class has been generated. - Follow the previous steps to genarate the Category model class in the same way: Type category in the table field and choose the many_many_category template. - Again the same process for the product_category pivot table,type product_category in the table field and choose the default template this time. **Important:** **Open the newly generated Category class file and remove ALL rules associated with root,rgt,left and level properties.** - With the models generated,proceed to the crud code generation: - Click GiixCrud Generator. - Type Product in the Model class field and keep the suggested controller ID,usually the same as the Model class name with first letter lowercase. - Choose the many_many_ product Code Template. - Preview if you want,and then Generate. - Follow the previous steps to genarate the Category crud files in the same way: Type Category in the Model class field and keep the suggested controller ID,choose the many_many_ category Code Template, preview if you want and then generate. - A minor modification for the newly generated _form.php file in the views/category folder is needed,open the file and follow the instructions in the comments right after the form->beginWidget. - This is it.Navigate to [application root]/category/admin_grid.Start by creating a root category node,then create more nodes. Create Products,and associate them with categories or vice versa. ##Note The image fields associated with the models do not depend on the database schema,their functionality originates in the fileimagebehavior. If you want to remove this feature,do the following.Open the model class file and delete the *_image property declaration in the beginning of the class file,the associated rule in the rules function,and the *ImgBehavior configuration.Open the _form.php files and remove the file fields.Last,delete the img folder. Spiros "drumaddict" Kabasakalis,December 11th 2011. ##Resources - [Giix]( ) - [Nested Set Model]( ) - [Nested Set Behavior Yii Extension]( ) - [jsTree]( ) - [jQuery Form Plugin]( ) - [File Image AR Behavior]( ) - [Fancybox]( ) - [Fancybox2]( ) (Read the licence) - [jQuery UI]( ) - [Chosen]( ) ##CHANGE LOG - **1.1 December 15th 2011** Fixed some wrong urls for the grid buttons in admin_grid.php and index_grid.php files.Not a big deal,you have probably fixed this already....