Yii Framework Forum: How to define location of views for the Yiic generated GRUDs - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

How to define location of views for the Yiic generated GRUDs Rate Topic: -----

#1 User is offline   SilentWarrior 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 29-July 09

Posted 29 July 2009 - 05:28 PM

Hey, I just fired up a new project, and made Yiic generate me models and gruds for 4 tables i had.

All worked fine, and, i have 4 controlelrs (one each table) and also 4 diferent directories for the views regarding those controllers. (all normal here, fully automated by Yiic)

Now my problem, in the Views directory, each of the tables views (for crud) are in their "private" directory, each containing several PHP files for the several actions we might need (create.php, list.php, etc), but, i want to keep them inside another directory called "crud" so it would be :

webApp/protected/views/crud/"tablename" ("tablename" beeing the name for the directory with all crud php files in it)
Instead of :
webApp/protected/views/"tablename"

Why? To keep things organised... say i had 50 tables instead of just 4.

If it would be possible for the Controllers too would be awsome, but, for now I just want to know how i can circumvent the "convention over configuration" for this specific case.

PS: From the example, the "site" controller can have their views inside a "site" directory because it uses them for actions, right? (cant seem to find a configuration for that), but i want to keep the code structure of each tables crud beeing in their own Controller instead of polutting it with more actions.
PS2: remember, i didnt change anything from the default output Yiic gives except for DB configuration to generate the crud and models for the 4 tables. And the "crud" folder, to keep things organized.

Regards
SilentWarrior
0

#2 User is offline   SilentWarrior 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 29-July 09

Posted 29 July 2009 - 05:38 PM

View PostSilentWarrior, on 29 July 2009 - 05:28 PM, said:

Hey, I just fired up a new project, and made Yiic generate me models and gruds for 4 tables i had.

All worked fine, and, i have 4 controlelrs (one each table) and also 4 diferent directories for the views regarding those controllers. (all normal here, fully automated by Yiic)

Now my problem, in the Views directory, each of the tables views (for crud) are in their "private" directory, each containing several PHP files for the several actions we might need (create.php, list.php, etc), but, i want to keep them inside another directory called "crud" so it would be :

webApp/protected/views/crud/"tablename" ("tablename" beeing the name for the directory with all crud php files in it)
Instead of :
webApp/protected/views/"tablename"

Why? To keep things organised... say i had 50 tables instead of just 4.

If it would be possible for the Controllers too would be awsome, but, for now I just want to know how i can circumvent the "convention over configuration" for this specific case.

PS: From the example, the "site" controller can have their views inside a "site" directory because it uses them for actions, right? (cant seem to find a configuration for that), but i want to keep the code structure of each tables crud beeing in their own Controller instead of polutting it with more actions.
PS2: remember, i didnt change anything from the default output Yiic gives except for DB configuration to generate the crud and models for the 4 tables. And the "crud" folder, to keep things organized.

Regards
SilentWarrior


Ah! The power of conventions over configurations, I just put all my controllers (for each of the tables) inside a folder called crud, and updated the links and it all started working again. Love it =)

For future reference, heres how i solved it.

Links updated to ("comentarios" is one of the table names):
array('label'=>'Comentarios', 'url'=>array('/crud/comentarios')

Controllers:
webApp/protected/controllers/crud/ComentariosController.php
Views :
webApp/protected/views/crud/comentarios/ (then the rest of view files here)
0

#3 User is offline   aztech 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 12-December 08
  • Location:Poland

Posted 29 July 2009 - 05:46 PM

I think you have to extend crud command. Please refer this cookbook: How to extend yiic shell commands for more detail. I think if you will create your own command with another path. I think you have to overwrite method generateView of CrudCommand.php and also
    public function generateView($source,$modelClass)
    {
        $model=CActiveRecord::model($modelClass);
        $table=$model->getTableSchema();
        $columns=$table->columns;
        unset($columns[$table->primaryKey]);
        if(!is_file($source))  // fall back to default ones
            $source=YII_PATH.'/cli/views/shell/crud/'.basename($source);
        return $this->renderFile($source,array(
            'ID'=>$table->primaryKey,
            'modelClass'=>$modelClass,
            'columns'=>$columns),true);
    }


and additionally in you "base controller" for all controllers you are using for "cruds", ypu have to modify methods:
getViewFile() and getViewPath().
I'm not complete idiot... some parts are missing!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users