mirror of
https://github.com/yiisoft/yii.git
synced 2026-03-09 09:36:56 +01:00
Added initial gii framework..
This commit is contained in:
72
framework/gii/generators/controller/ControllerCode.php
Normal file
72
framework/gii/generators/controller/ControllerCode.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
class ControllerCode extends CCodeModel
|
||||
{
|
||||
public $controller;
|
||||
public $actions='index';
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return array(
|
||||
array('controller, actions', 'filter', 'filter'=>'trim'),
|
||||
array('controller, actions', 'required'),
|
||||
array('controller', 'match', 'pattern'=>'/^\w+(\w+\\/)*$/', 'message'=>'{attribute} should only contain word characters and slashes.'),
|
||||
array('actions', 'match', 'pattern'=>'/^\w+[\w\s,]*$/', 'message'=>'{attribute} should only contain word characters, spaces and commas.'),
|
||||
);
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return array(
|
||||
'controller'=>'Controller ID',
|
||||
'actions'=>'Action IDs',
|
||||
);
|
||||
}
|
||||
|
||||
public function prepare($templatePath)
|
||||
{
|
||||
$this->files=array();
|
||||
|
||||
$controllerFile=Yii::app()->controllerPath;
|
||||
if(($pos=strrpos($this->controller,'/'))!==false)
|
||||
$controllerFile.='/'.substr($this->controller,0,$pos);
|
||||
$controllerFile.='/'.$this->getControllerClass().'.php';
|
||||
|
||||
$this->files[]=new CCodeFile(
|
||||
$controllerFile,
|
||||
$this->render($templatePath.'/controller.php')
|
||||
);
|
||||
|
||||
foreach($this->getActionIDs() as $action)
|
||||
{
|
||||
$this->files[]=new CCodeFile(
|
||||
Yii::app()->viewPath.'/'.$this->controller.'/'.$action.'.php',
|
||||
$this->render($templatePath.'/view.php', array('action'=>$action))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function getActionIDs()
|
||||
{
|
||||
$actions=preg_split('/[\s,]+/',$this->actions,-1,PREG_SPLIT_NO_EMPTY);
|
||||
$actions=array_unique($actions);
|
||||
sort($actions);
|
||||
return $actions;
|
||||
}
|
||||
|
||||
public function getControllerID()
|
||||
{
|
||||
if(($pos=strrpos($this->controller,'/'))!==false)
|
||||
return substr($this->controller,$pos+1);
|
||||
else
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
public function getControllerClass()
|
||||
{
|
||||
if(($pos=strrpos($this->controller,'/'))!==false)
|
||||
return ucfirst(substr($this->controller,$pos+1)).'Controller';
|
||||
else
|
||||
return ucfirst($this->controller).'Controller';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user