merge from 1.0.

This commit is contained in:
qiang.xue
2009-07-21 21:03:45 +00:00
parent 6bf45d462e
commit 5c60a2fcfa
4 changed files with 28 additions and 14 deletions

View File

@@ -20,10 +20,12 @@
class ControllerCommand extends CConsoleCommand
{
/**
* @var string the template file for the controller class.
* Defaults to null, meaning using 'framework/cli/views/shell/controller/controller.php'.
* @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 $templateFile;
public $templatePath;
public function getHelp()
{
@@ -118,11 +120,11 @@ EOD;
$args[]='index';
$actions=array_unique(array_splice($args,1));
$templateFile=$this->templateFile===null?YII_PATH.'/cli/views/shell/controller/controller.php':$this->templateFile;
$templatePath=$this->templatePath===null?YII_PATH.'/cli/views/shell/controller':$this->templatePath;
$list=array(
basename($controllerFile)=>array(
'source'=>$templateFile,
'source'=>$templatePath.DIRECTORY_SEPARATOR.'controller.php',
'target'=>$controllerFile,
'callback'=>array($this,'generateController'),
'params'=>array($controllerClass, $actions),
@@ -133,8 +135,10 @@ EOD;
foreach($actions as $name)
{
$list[$name.'.php']=array(
'source'=>YII_PATH.'/cli/views/shell/controller/view.php',
'source'=>$templatePath.DIRECTORY_SEPARATOR.'view.php',
'target'=>$viewPath.DIRECTORY_SEPARATOR.$name.'.php',
'callback'=>array($this,'generateAction'),
'params'=>array(),
);
}
@@ -158,6 +162,15 @@ EOD;
public function generateController($source,$params)
{
if(!is_file($source)) // fall back to default ones
$source=YII_PATH.'/cli/views/shell/controller/'.basename($source);
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
$source=YII_PATH.'/cli/views/shell/controller/'.basename($source);
return $this->renderFile($source,array(),true);
}
}