Difference between #1 and #2 of
How to extend yiic shell commands

Revision #2 has been created by wei on Oct 26, 2010, 3:08:03 AM with the memo:

formatting, tags
« previous (#1)


Title unchanged

How to extend yiic shell commands

Category unchanged


Yii version unchanged

Tags changed


Content changed

While `yiic shell` tool is very convenient at generating skeleton code in our application, the generated code is not always what we want. For example, we may want the generated code to carry specific copyright information; we may want to use our own coding style; we may want to add more features; and so on. All these can be accomplished easily in Yii.

In the following, we explain how to extend the `model` and `crud` commands, which are the two most powerful `yiic shell` commands.

## Extending `model` Command

When we create our initial application code using `yiic webapp` command, we may find there is a directory called `protected/commands/shell`. This is the place where we shall store the extended shell command classes.
We should be able to use our newly created model command now. Enter the `yiic shell` and type `help`. We should see a list of available shell commands which now include a new command called `mymodel`. Try using this command the same way as using the original `model` command (e.g. `mymodel Post`). We should see that the generated model class is using the template we just wrote.

## Extending `crud` Command

Extending the `crud` command is only a bit more complex than extending the `model` command. We create a file named `protected/commands/shell/MycrudCommand.php` as follows,

2 0
Viewed: 26 100 times
Version: 1.1
Category: Tutorials
Tags: yiic
Written by: qiang
Last updated by: wei
Created on: Jul 21, 2009
Last updated: 7 years ago
Update Article


View all history