Yii Framework v1.1.10 绫诲弬鑰

CCodeGenerator

system.gii
缁ф壙 class CCodeGenerator » CController » CBaseController » CComponent
婧愯嚜 1.1.2
鐗堟湰 $Id: CCodeGenerator.php 3426 2011-10-25 00:01:09Z alexander.makarow $
婧愮爜 framework/gii/CCodeGenerator.php
CCodeGenerator鏄悇绉嶄唬鐮佺敓鎴愬櫒绫荤殑鍩虹被銆

CCodeGenerator鏄竴涓帶鍒跺櫒锛屽畠涓轰簡浠g爜鐢熸垚鐨勭洰鐨勯 瀹氫箟浜嗚嫢骞插姩浣溿傛淳鐢熺被涓昏闇瑕侀厤缃codeModel 灞炴у拰瑕嗙洊getSuccessMessage鏂规硶銆傚墠鑰 鎸囧畾浜嗙敓鎴愬櫒灏嗕娇鐢ㄥ摢涓涓唬鐮佹ā鍨嬶紙鎵╁睍鑷CCodeModel锛夛紝 鑰屽悗鑰呭垯瀹氫箟浜嗗綋浠g爜鏂囦欢琚垚鍔熺敓鎴愬悗杩斿洖鐨勯渶瑕 鏄剧ず鐨勬垚鍔熶俊鎭

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
action CAction the action currently being executed, null if no active action. CController
actionParams array Returns the request parameters that will be used for action parameter binding. CController
cachingStack CStack stack of COutputCache objects CController
clips CMap Returns the list of clips. CController
codeModel string 浠g爜妯″瀷绫汇傚畠鍙互鏄竴涓被鐨勫悕瀛楋紙濡傛灉璇ョ被鍙互琚嚜鍔ㄥ姞杞斤級 鎴栦竴涓寚鍚戠被鏂囦欢鐨勮矾寰勫埆鍚嶃 瀛愮被蹇呴』浣跨敤涓涓叿浣撶殑鍊奸厤缃繖涓睘鎬с CCodeGenerator
defaultAction string the name of the default action. CController
id string ID of the controller CController
layout string 鐢熸垚鍣ㄤ娇鐢ㄧ殑甯冨眬銆傞粯璁ゅ兼槸鈥済enerator鈥濄 CCodeGenerator
module CWebModule the module that this controller belongs to. CController
pageTitle string 椤甸潰鏍囬 CCodeGenerator
route string the route (module ID, controller ID and action ID) of the current request. CController
templates array 鍙敤鐨勪唬鐮佹ā鏉跨殑鍒楄〃 (name=>path) CCodeGenerator
uniqueId string the controller ID that is prefixed with the module ID (if any). CController
viewPath string 杩斿洖鐢熸垚鍣ㄧ殑瑙嗗浘鐨勮矾寰勩 CCodeGenerator

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() CController
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
accessRules() Returns the access rules for this controller. CController
actionCode() 浠g爜棰勮鍔ㄤ綔銆 CCodeGenerator
actionDiff() 浠g爜宸紓鍔ㄤ綔銆 CCodeGenerator
actionIndex() 鐢熸垚浠g爜鐨勫姩浣溿 CCodeGenerator
actions() Returns a list of external action classes. CController
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
beginCache() Begins fragment caching. CBaseController
beginClip() Begins recording a clip. CBaseController
beginContent() Begins the rendering of content that is to be decorated by the specified view. CBaseController
beginWidget() Creates a widget and executes it. CBaseController
behaviors() Returns a list of behaviors that this controller should behave as. CController
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
clearPageStates() Removes all page states. CController
createAbsoluteUrl() Creates an absolute URL for the specified action defined in this controller. CController
createAction() Creates the action instance based on the action name. CController
createUrl() Creates a relative URL for the specified action defined in this controller. CController
createWidget() Creates a widget and initializes it. CBaseController
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
endCache() Ends fragment caching. CBaseController
endClip() Ends recording a clip. CBaseController
endContent() Ends the rendering of content. CBaseController
endWidget() Ends the execution of the named widget. CBaseController
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
filterAccessControl() The filter method for 'accessControl' filter. CController
filterAjaxOnly() The filter method for 'ajaxOnly' filter. CController
filterPostOnly() The filter method for 'postOnly' filter. CController
filters() Returns the filter configurations. CController
forward() Processes the request using another controller action. CController
getAction() 杩斿洖the action currently being executed, null if no active action. CController
getActionParams() Returns the request parameters that will be used for action parameter binding. CController
getCachingStack() 杩斿洖stack of COutputCache objects CController
getClips() Returns the list of clips. CController
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getId() 杩斿洖ID of the controller CController
getLayoutFile() Looks for the layout view script based on the layout name. CController
getModule() 杩斿洖the module that this controller belongs to. It returns null if the controller does not belong to any module CController
getPageState() Returns a persistent page state value. CController
getPageTitle() 杩斿洖椤甸潰鏍囬 CCodeGenerator
getRoute() 杩斿洖the route (module ID, controller ID and action ID) of the current request. CController
getUniqueId() 杩斿洖the controller ID that is prefixed with the module ID (if any). CController
getViewFile() Looks for the view file according to the given view name. CController
getViewPath() 杩斿洖鐢熸垚鍣ㄧ殑瑙嗗浘鐨勮矾寰勩 CCodeGenerator
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
init() Initializes the controller. CController
invalidActionParams() This method is invoked when the request parameters do not satisfy the requirement of the specified action. CController
isCachingStackEmpty() Returns whether the caching stack is empty. CController
missingAction() Handles the request whose action is not recognized. CController
processDynamicOutput() Postprocesses the dynamic output. CController
processOutput() Postprocesses the output generated by render(). CController
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
recordCachingAction() Records a method call when an output cache is in effect. CController
redirect() Redirects the browser to the specified URL or route (controller/action). CController
refresh() Refreshes the current page. CController
render() Renders a view with a layout. CController
renderClip() Renders a named clip with the supplied parameters. CController
renderDynamic() Renders dynamic content returned by the specified callback. CController
renderDynamicInternal() This method is internally used. CController
renderFile() Renders a view file. CBaseController
renderInternal() Renders a view file. CBaseController
renderPartial() Renders a view. CController
renderText() Renders a static text string. CController
resolveViewFile() Finds a view file based on its name. CController
run() Runs the named action. CController
runAction() Runs the action after passing through all filters. CController
runActionWithFilters() Runs an action with the specified filters. CController
setAction() 璁剧疆the action currently being executed. CController
setPageState() Saves a persistent page state value. CController
setPageTitle() 璁剧疆the page title. CController
setViewPath() 璁剧疆鐢熸垚鍣ㄧ殑瑙嗗浘鐨勮矾寰勩 CCodeGenerator
widget() Creates a widget and executes it. CBaseController

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
afterAction() This method is invoked right after an action is executed. CController
afterRender() This method is invoked after the specified is rendered by calling render(). CController
beforeAction() This method is invoked right before an action is to be executed (after all possible filters.) CController
beforeRender() This method is invoked at the beginning of render(). CController
createActionFromMap() Creates the action instance based on the action map. CController
loadPageStates() Loads page states from a hidden input. CController
prepare() 鍑嗗浠g爜妯″瀷銆 CCodeGenerator
replaceDynamicOutput() Replaces the dynamic content placeholders with actual content. CController
savePageStates() Saves page states as a base64 string. CController

灞炴ц缁

codeModel 灞炴
public string $codeModel;

浠g爜妯″瀷绫汇傚畠鍙互鏄竴涓被鐨勫悕瀛楋紙濡傛灉璇ョ被鍙互琚嚜鍔ㄥ姞杞斤級 鎴栦竴涓寚鍚戠被鏂囦欢鐨勮矾寰勫埆鍚嶃 瀛愮被蹇呴』浣跨敤涓涓叿浣撶殑鍊奸厤缃繖涓睘鎬с

layout 灞炴
public string $layout;

鐢熸垚鍣ㄤ娇鐢ㄧ殑甯冨眬銆傞粯璁ゅ兼槸鈥済enerator鈥濄

pageTitle 灞炴
public string getPageTitle()
public void setPageTitle(string $value)

椤甸潰鏍囬

templates 灞炴
public array $templates;

鍙敤鐨勪唬鐮佹ā鏉跨殑鍒楄〃 (name=>path)

viewPath 灞炴
public string getViewPath()
public void setViewPath(string $value)

杩斿洖鐢熸垚鍣ㄧ殑瑙嗗浘鐨勮矾寰勩 杩斿洖鐢熸垚鍣ㄧ被鏂囦欢鎵鍦ㄧ洰褰曚笅鐨勨渧iews鈥濆瓙鐩綍銆

鏂规硶璇︾粏

actionCode() 鏂规硶
public void actionCode()
婧愮爜锛 framework/gii/CCodeGenerator.php#80 (鏄剧ず)
public function actionCode()
{
    
$model=$this->prepare();
    if(isset(
$_GET['id']) && isset($model->files[$_GET['id']]))
    {
        
$this->renderPartial('/common/code', array(
            
'file'=>$model->files[$_GET['id']],
        ));
    }
    else
        throw new 
CHttpException(404,'Unable to find the code you requested.');
}

浠g爜棰勮鍔ㄤ綔銆 姝ゅ姩浣滄樉绀烘寚瀹氱殑宸茬敓鎴愪唬鐮併

actionDiff() 鏂规硶
public void actionDiff()
婧愮爜锛 framework/gii/CCodeGenerator.php#97 (鏄剧ず)
public function actionDiff()
{
    
Yii::import('gii.components.TextDiff');

    
$model=$this->prepare();
    if(isset(
$_GET['id']) && isset($model->files[$_GET['id']]))
    {
        
$file=$model->files[$_GET['id']];
        if(!
in_array($file->type,array('php''txt','js','css')))
            
$diff=false;
        else if(
$file->operation===CCodeFile::OP_OVERWRITE)
            
$diff=TextDiff::compare(file_get_contents($file->path), $file->content);
        else
            
$diff='';

        
$this->renderPartial('/common/diff',array(
            
'file'=>$file,
            
'diff'=>$diff,
        ));
    }
    else
        throw new 
CHttpException(404,'Unable to find the code you requested.');
}

浠g爜宸紓鍔ㄤ綔銆 姝ゅ姩浣滄樉绀烘柊鐢熸垚鐨勪唬鐮佷笌宸叉湁浠g爜涔嬮棿鐨勪笉鍚屻

actionIndex() 鏂规硶
public void actionIndex()
婧愮爜锛 framework/gii/CCodeGenerator.php#62 (鏄剧ず)
public function actionIndex()
{
    
$model=$this->prepare();
    if(
$model->files!=array() && isset($_POST['generate'], $_POST['answers']))
    {
        
$model->answers=$_POST['answers'];
        
$model->status=$model->save() ? CCodeModel::STATUS_SUCCESS CCodeModel::STATUS_ERROR;
    }

    
$this->render('index',array(
        
'model'=>$model,
    ));
}

鐢熸垚浠g爜鐨勫姩浣溿 杩欎釜鍔ㄤ綔鏄剧ず浠g爜鐢熸垚鐨勭晫闈€ 瀛愮被涓昏闇瑕佹彁渚'index'瑙嗗浘浠ヤ负浠g爜鐢熸垚 鏀堕泦鐢ㄦ埛鍙傛暟銆

getPageTitle() 鏂规硶
public string getPageTitle()
{return} string 椤甸潰鏍囬
婧愮爜锛 framework/gii/CCodeGenerator.php#51 (鏄剧ず)
public function getPageTitle()
{
    return 
'Gii - '.ucfirst($this->id).' Generator';
}

getViewPath() 鏂规硶
public string getViewPath()
{return} string 鐢熸垚鍣ㄧ殑瑙嗗浘鐨勮矾寰勩
婧愮爜锛 framework/gii/CCodeGenerator.php#126 (鏄剧ず)
public function getViewPath()
{
    if(
$this->_viewPath===null)
    {
        
$class=new ReflectionClass(get_class($this));
        
$this->_viewPath=dirname($class->getFileName()).DIRECTORY_SEPARATOR.'views';
    }
    return 
$this->_viewPath;
}

杩斿洖鐢熸垚鍣ㄧ殑瑙嗗浘鐨勮矾寰勩 杩斿洖鐢熸垚鍣ㄧ被鏂囦欢鎵鍦ㄧ洰褰曚笅鐨勨渧iews鈥濆瓙鐩綍銆

prepare() 鏂规硶
protected void prepare()
婧愮爜锛 framework/gii/CCodeGenerator.php#147 (鏄剧ず)
protected function prepare()
{
    if(
$this->codeModel===null)
        throw new 
CException(get_class($this).'.codeModel property must be specified.');
    
$modelClass=Yii::import($this->codeModel,true);
    
$model=new $modelClass;
    
$model->loadStickyAttributes();
    if(isset(
$_POST[$modelClass]))
    {
        
$model->attributes=$_POST[$modelClass];
        
$model->status=CCodeModel::STATUS_PREVIEW;
        if(
$model->validate())
        {
            
$model->saveStickyAttributes();
            
$model->prepare();
        }
    }
    return 
$model;
}

鍑嗗浠g爜妯″瀷銆

setViewPath() 鏂规硶
public void setViewPath(string $value)
$value string 鐢熸垚鍣ㄧ殑瑙嗗浘鐨勮矾寰勩
婧愮爜锛 framework/gii/CCodeGenerator.php#139 (鏄剧ず)
public function setViewPath($value)
{
    
$this->_viewPath=$value;
}

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.