This extension implements CRUD operations on the DB tables using a single controller.
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.0.2 or above - tested only at this version
Warning!!! ¶
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!
Installation ¶
Extract the release catalogue 'crud' under
protected/extensions
Add to your 'config/main':
[php]
'controllerMap'=>array(
'crud'=>array(
'class'=>'application.extensions.crud.CrudController',
)
),
'components'=>array(
..............
'crudMessages'=>array(
'class'=>'CPhpMessageSource',
'basePath'=>'protected/extensions/crud/messages',
),
..............
[php]
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).
Usage ¶
call by the adddress:
{baseUrl}/crud/{action}/model/{modelName}[/id/{recordId}],
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)
Restrictions ¶
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.
I have tested:
not work for me:
-requires tables in ucase User all my tables are user in lowercase
-not exist 'name' table
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 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!
Max
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.