yiic-crud-templates on application-path

Hello all,

make it sense to have the possibility to define a place for custom

view-files to render yiic-crud / model commands in application-folder/config?

Example: on a large project i would like it, to define the controller-

template/Crud-Templates so that it will better fits my needs. I copy the

standard template to e.g app/view/cli/views/shell/curd or …/controller

and make some modifications.

On calling the yiic-crud-command it first looks in the application-folder for

these templates and if not found take the standard-templates.

What do you think of this approach?

Greetings from Germany

me23

I also vote for this feature. But I think that all yiic templates should be customizable not only crud but e.g. model.

Maybe there could be also possibility to define some parameters when generating crud such a "all", "list", "show" etc. 

yiic does support customized template views. Simply put your template files under "framework/cli/views/shell/crud" and they will be used. For more details, see doc of CrudCommand::templatePath.

Thanks qiang,

but if i put the template under "framework/cli/views/shell/crud" they

will be overwritten by next yii-update and would globally used for all

projects. But i think it would be helpfull to define these Templates

for each Webapp.

Also i tried your suggestion about templatePath. It works but now

it only takes absolute path. I think it will be better to allow the alias

-way (application.commands.shell.crud). I put this code



if(($pos=strrpos($templatePath,DIRECTORY_SEPERATOR))===false){


	$templatePath=Yii::getPathOfAlias($templatePath);


}


in CurdCommand.php Line 90 to use the Alias-Way.

The Comment of templatePath says:

Quote

* If you set this path and some views are missing in the directory,
  • the default views will be used.

so i suggest to define always the templatePath to "application.commands.shell.crud" so if someone like to change the crud-template for one project he only have to put the files in that directory.

If the directory is empty, the command uses the default-templates…

What do you think?

Greetings from Germany

me23

Sorry, I was wrong. In order to use your own set of crud templates, you will have to extend CrudCommand, put the child class under protected/commands/shell.

In your child class' constructor, you can set templatePath by calling Yii::getPathOfAlias.

Thanks qiang,

works like a charm :slight_smile:

me23

Hi me23,

Could you perhaps share your example? I tried to do the same thing (extend CrudCommand) but I had to include the CrudCommand.php explicitly in order to avoid an error message (Bad File Descriptor).

Hi Sacha,

sure here you are:

first create a new command under <your-app>/protected/commands/shell

it look lilke this:



Yii::import('system.cli.commands.shell.CrudCommand');





class yourCrudCommand extends CrudCommand


{	


	public function __construct(){


		$this->templatePath = Yii::getPathOfAlias("application.commands.views.shell.crud");


	}


}


now copy the view-files you like to change from framework path (<yii>/framework/cli/views/crud) and put it in <your-app>/protected/command/views/shell/crud. Here you can modify the templates like you wish.

After that go in console to <your-app> path and (re-) call yiic from there, type help.

Now you should see a new command entry for 'yourCrudCommand'.

By calling the new command, yiic should now take your templates from

application folder for generation.

Thats it.

Greetings from Germany

me23

Hi me23,

Thanks for the example! Now my CrudCommand works like a charm…

Cheers, Sacha

Great! Works very fine.

But is there no way to specify ‘templatePath’ via shell or config/console.php?

Or why is ‘templatePath’ a class property of CrudCommand?

Best regards,

schmunk

Yeah, actually it is possible to configure it in console.php by setting "commandMap" property of CConsoleApplication.

You may also refer to http://www.yiiframework.com/doc/cookbook/41/