Yii 1.1: crudcontroller

Create-read-update-delete operations on every tables in DB by a single controller

This extension implements CRUD operations on the DB tables using a single controller.




  • Yii 1.0.2 or above - tested only at this version


Be careful with access control! You should set restricted access to this controller, or list allowed models in filters, or organize access control to tables at the database level (if possible). Otherwise one can manipulate with your forbidden datatables over it!


  • Extract the release catalogue 'crud' under protected/extensions

  • Add to your 'config/main':





The last ('crudMessages') is needed if you have created corresponding message file 'yii.php' and dispose it in the corresponding language directory. At present only Russian translation is available.

  • Define 'pluralName' property to all of your models you want to manipulate over this controller - if wanna get nice titles!

  • Define all needed relaitons in your models via Model::relations. Notice! Only 'BELONGS_TO' type taken into account in this version.

  • View files 'list.php', 'createUpdate.php' use CSS classes defined in 'main.css', registered in layout. You may redefine them in your own css-file and register this one (after publishing).


call by the adddress:


where {action} = create|list|update|delete|

{modelName} - your model's name in lowercase

if needed (for update&delete), set the value of record id you want to update or delete:

{recordId} - record id (if needed)


At present can work with models having:

  • ONLY 'BELONGS_TO' relations;

  • ONE primary key named 'id';

  • refered table MUST have a field named 'name' - that is the field which is displayed in the relation

I learnt from someone that references can be emulated even on MyISAM tables using 'COMMENT' SQL declaration, but I didn't check.

It works definitely on InnoDB with real references - this is a fact, and it's enough for me...

Change Log

April 11, 2009

  • Initial release.

Total 1 comment

#1761 report it
megabr at 2009/04/14 08:08am
I have tested:

not work for me: -requires tables in ucase User all my tables are user in lowercase -not exist 'name' table - I don have any table 'id'

but same tips for crud: I am using Im my CRUD script this 'standard'(my standards :) )

for default when creating table I use: for primary key: table and _id for identify; table_id

table user have:

user_id user mail group_id

table group have

group_id group description

that when generating my crud:

I kknow all relations between tables trying split every column name;

I use the tablename present as the field/column to show in select/show,create. update.

if(!$column->isPrimaryKey AND $col[1]=='id')
{                    $relations.="\n\t\t\t '{$col[0]}'=>array(self::BELONGS_TO, '{$col[0]}','{$column->name}'),";

if you want can you open a topic for exchange ideias about CRUD, I currently develop the http://www.yiiframework.com/extension/modulegen/

generator of CRUD in the module way. regards!


Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: kvl
  • Category: Database
  • Votes: +1
  • Downloaded: 982 times
  • Created on: Apr 11, 2009
  • Last updated: Jul 5, 2009