Monday, January 9, 2012

How to Use Crud Generator (Gii Tool - Yii Code Generator)

After I have discussed previously the Controller of making post "How to Use Controller Generator (Gii Tool - Yii Code Generator)" and also the model on the post "How to Use Model Generator (Gii Tool - Yii Code Generator)", I would go again in How to Use Crud Generator (Gii Tool - Yii Code Generator). CRUD (Create Read Update Delete) generator generates a controller and views that implement CRUD operations for the specified data model. Please follow these steps below to use this generator:
  1. Open yii code generator - http://localhost/webappname/index.php?r=gii/default/login
  2. Select Crud Generator and enter the name of your model you created in the Model Generator. It should be noted that the use of uppercase and lowercase letters should be tailored to the name of the Model Class we have made to the Model Generator. In the previous example the discussion of Model Generator, Model name is its Class User (letter U in the word using the letters of the user). And select preview and cetang all existing Code File and click generate.

    On Crud Generator you will see the results on protected\views\user\

    generated controllers\UserController.php
    generated views\user\_form.php
    generated views\user\_search.php
    generated views\user\_view.php
    generated views\user\admin.php
    generated views\user\create.php
    generated views\user\index.php
    generated views\user\update.php
    generated views\user\view.php

  3. To view the results please click on try it now or go on http://localhost/webappname/index.php/user
  4. To operate the CRUD (Create-Read-Update-Delete), you must first login. Open http://localhost/webappname/index.php/site/login

  5. Then go again http://localhost/webappname/index.php/user/. You can see there is not a user.
  6. Have you gone to http://localhost/webappname/index.php/user/create. to create a new user - Create User
  7. If you have made, you can see it back in http://localhost/webappname/index.php/user/index - User List
  8. To Manage User (Create-Read-Update-Delete), you can open it in http://localhost/webappname/index.php/user/admin - Manage Users (View, Update, Delete)
Thus means that you have successfully created a web application CRUD (Create-Read-Update-Delete)

5 comments:

  1. Nice article. It helped me a lot. I didn't understand these concepts after reading the yii book. But your article was pretty easy to understand. Thanks for sharing.

    ReplyDelete
  2. Nice article. I'm extremely new to Yii. I'm playing with a fresh install as I type this. Anyway, for clarification, I'm guessing that I'll want to setup at least one user after the model user / crud user step, but before the creating roles, assigning admin to the first created user, etc. under authManager. Does that make sense?

    ReplyDelete
  3. Nice article.... :)
    It helped me a lot. Your article was very easy to understand....
    Thanks

    ReplyDelete
  4. It is a great post for every blog and for me. Obviously I want to say that this is very important post for learn. Thanks..

    Hire Yii Framework Developers

    ReplyDelete

Yii Framework Tutorials