yii-bootstrap / demo / yii / cli / commands / shell / ControllerCommand.php

 * ControllerCommand class file.
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 * @version $Id$

 * ControllerCommand generates a controller class.
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @version $Id$
 * @package system.cli.commands.shell
 * @since 1.0
class ControllerCommand extends CConsoleCommand
	 * @var string the directory that contains templates for the model command.
	 * Defaults to null, meaning using 'framework/cli/views/shell/controller'.
	 * If you set this path and some views are missing in the directory,
	 * the default views will be used.
	public $templatePath;

	public function getHelp()
		return <<<EOD
  controller <controller-ID> [action-ID] ...

  This command generates a controller and views associated with
  the specified actions.

 * controller-ID: required, controller ID, e.g., 'post'.
   If the controller should be located under a subdirectory,
   please specify the controller ID as 'path/to/ControllerID',
   e.g., 'admin/user'.

   If the controller belongs to a module, please specify
   the controller ID as 'ModuleID/ControllerID' or
   'ModuleID/path/to/Controller' (assuming the controller is
   under a subdirectory of that module).

 * action-ID: optional, action ID. You may supply one or several
   action IDs. A default 'index' action will always be generated.

 * Generates the 'post' controller:
        controller post

 * Generates the 'post' controller with additional actions 'contact'
   and 'about':
        controller post contact about

 * Generates the 'post' controller which should be located under
   the 'admin' subdirectory of the base controller path:
        controller admin/post

 * Generates the 'post' controller which should belong to
   the 'admin' module:
        controller admin/post

NOTE: in the last two examples, the commands are the same, but
the generated controller file is located under different directories.
Yii is able to detect whether 'admin' refers to a module or a subdirectory.


	 * Execute the action.
	 * @param array command line parameters specific for this command
	 * @return integer|null non zero application exit code for help or null on success
	public function run($args)
			echo "Error: controller name is required.\n";
			echo $this->getHelp();
			return 1;






				'params'=>array($controllerClass, $actions),

		foreach($actions as $name)
				'params'=>array('controller'=>$controllerClass, 'action'=>$name),


		if($module instanceof CWebModule)

		echo <<<EOD

Controller '{$controllerID}' has been created in the following file:

You may access it in the browser using the following URL:


	public function generateController($source,$params)
		if(!is_file($source))  // fall back to default ones
		return $this->renderFile($source,array('className'=>$params[0],'actions'=>$params[1]),true);

	public function generateAction($source,$params)
		if(!is_file($source))  // fall back to default ones
		return $this->renderFile($source,$params,true);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.