Yii CRUD generator and plural forms

yii logoYii framework has a really nice CRUD generator that can speed up building back-end applications, which tend to be rather similar and therefore repetitive. If you prepare reasonable taxonomy of the underlying database tables, it also manages the page headers pretty well. If your table is called album, for instance, it will generate a page for editing albums with a header “Edit Album #1”, an index page called “List Albums” or the management page called “Manage Albums”. As you can see, it will even handle the plural forms. However, this works fine for English projects, but may not be desirable for other languages.

What I usually do is find the method called pluralize() in framework/gii/CCodeModel.php and basically disable the method by changing it like this:

Another way of dealing with this is to remove the generated names based on the table names completely. You can edit the files like:

framework/gii/generators/crud/templates/default/admin.php
framework/gii/generators/crud/templates/default/create.php
framework/gii/generators/crud/templates/default/update.php
etc.

prior to making use of the CRUD generator, and change the H1 headers and the labels to something more generic (i.e. simply “Edit”, “View”, “Update row #1”).

Tagged with: , ,