Yii Framework v1.1.10 绫诲弬鑰

GiiModule

system.gii
缁ф壙 class GiiModule » CWebModule » CModule » CComponent
婧愯嚜 1.1.2
鐗堟湰 $Id: GiiModule.php 3426 2011-10-25 00:01:09Z alexander.makarow $
婧愮爜 framework/gii/GiiModule.php
GiiModule 鏄竴涓ā鍧楋紝瀹冩彁渚涘熀浜嶹eb鐨勪唬鐮佺敓鎴愬姛鑳姐

瑕佷娇鐢℅iiModule锛屼綘闇瑕佽薄涓嬮潰杩欐牱灏嗗畠鍖呭惈鍦ㄥ簲鐢ㄧ▼搴忕殑閰嶇疆鏂囦欢涓細
return array(
    ......
    'modules'=>array(
        'gii'=>array(
            'class'=>'system.gii.GiiModule',
            'password'=>***choose a password***
        ),
    ),
)


鍥犱负GuiiModule浼氬湪鏈嶅姟鍣ㄤ笂鐢熸垚鏂扮殑浠g爜鏂囦欢锛屼綘搴旇浠呭湪鑷繁鐨 杩涜寮鍙戠殑鏈哄櫒涓婁娇鐢ㄥ畠銆備负浜嗛槻姝㈠埆浜轰娇鐢ㄦ妯″潡锛屽畠闇瑕佷綘鍦ㄩ厤 缃枃浠朵腑鎸囧畾涓涓畨鍏ㄥ瘑鐮併傚綋浣犻氳繃娴忚鍣ㄨ闂瓽iiModule鏃讹紝浣 灏嗚鎻愮ず闇瑕佽緭鍏ユ纭殑瀵嗙爜銆

榛樿鎯呭喌涓嬶紝GiiModule鍙兘閫氳繃鏈湴涓绘満璁块棶銆 濡傛灉浣犳兂鍦ㄥ叾浠栨満 鍣ㄤ笂璁块棶锛屽彲浠ラ厤缃叾 ipFilters灞炴т互瀹炵幇姝ょ洰鐨勩

閫氳繃涓婇潰鐨勯厤缃紝浣犲氨鍙互璁块棶GiiModule浜嗐傚湪浣犵殑娴忚鍣ㄤ腑璁块棶姝 URL:

http://localhost/path/to/index.php?r=gii

濡傛灉鎮ㄧ殑搴旂敤绋嬪簭鏄娇鐢ㄤ竴浜涜嚜瀹氫箟URL瑙勫垯鐨勮矾寰勬牸寮忕殑URL锛 鎮ㄥ湪鎮ㄧ殑搴旂敤绋嬪簭閰嶇疆涓坊鍔犱互涓婾RL浠ヨ闂瓽iiModule:
'components'=>array(
    'urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
            'gii'=>'gii',
            'gii/<controller:\w+>'=>'gii/<controller>',
            'gii/<controller:\w+>/<action:\w+>'=>'gii/<controller>/<action>',
            ...other rules...
        ),
    )
)


鐜板湪浣犲彲浠ラ氳繃涓嬮潰鐨刄RL璁块棶鍒癎iiModule锛

http://localhost/path/to/index.php/gii

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
assetsUrl string 鍖呭惈浜咷ii鐨勬墍鏈夎祫婧愭枃浠(asset files)鐨勫熀鍑哢RL銆 GiiModule
basePath string 杩斿洖妯″潡鏍圭洰褰曘 CModule
behaviors array the behaviors that should be attached to the module. CModule
components array 杩斿洖搴旂敤缁勪欢銆 CModule
controllerMap array mapping from controller ID to controller configurations. CWebModule
controllerPath string the directory that contains the controller classes. CWebModule
defaultController string the ID of the default controller for this module. CWebModule
description string Returns the description of this module. CWebModule
generatorPaths array 涓涓矾寰勫埆鍚嶇殑鍒楄〃锛屽畠浠寚鍚戝寘鍚悇绉嶄唬鐮佺敓鎴愬櫒鐨 鐩綍銆備竴涓崟涓鐨勮矾寰勫埆鍚嶆寚鍚戠殑鐩綍鍙互鍖呭惈澶氫釜浠g爜鐢熸垚鍣紝姣 涓唬鐮佺敓鎴愬櫒瀛樻斁鍦ㄤ互鐢熸垚鍣ㄥ悕瀛楀懡鍚嶇殑瀛愮洰褰曚腑銆 榛樿鍊兼槸('application. GiiModule
id string 杩斿洖妯″潡ID銆 CModule
ipFilters array IP杩囨护鍣ㄧ殑鍒楄〃锛屾寚瀹氬摢浜汭P鍏佽璁块棶GiiModule銆 姣忎釜鏁扮粍鍏冪礌琛ㄨ揪涓涓崟涓鐨勮繃婊ゅ櫒銆備竴涓繃婊ゅ櫒鏃㈠彲浠ユ槸涓涓 IP鍦板潃锛屼篃鍙互鏄竴涓惈鏈夐氶厤绗︾殑鍦板潃锛堜緥濡傦細192. GiiModule
layout mixed the layout that is shared by the controllers inside this module. CWebModule
layoutPath string the root directory of layout files. CWebModule
modulePath string 杩斿洖鍖呭惈搴旂敤绋嬪簭妯″潡鐨勭洰褰曘 CModule
modules array 杩斿洖搴旂敤绋嬪簭褰撳墠宸茬粡瀹夎鐨勬ā鍧椼 CModule
name string Returns the name of this module. CWebModule
newDirMode integer 涓烘柊鐢熸垚鐨勭洰褰曡缃殑鏉冮檺銆 杩欎釜鍊煎皢琚玃HPchmod鍑芥暟浣跨敤銆 榛樿鍊兼槸0777锛岃〃绀烘鏂囦欢瀵规墍鏈夌敤鎴烽兘鏄彲璇汇佸啓銆佹墽琛岀殑銆 GiiModule
newFileMode integer 涓烘柊鐢熸垚鐨勪唬鐮佹枃浠惰缃殑鏉冮檺銆 杩欎釜鍊煎皢琚玃HPchmod鍑芥暟浣跨敤銆 榛樿鍊兼槸0666锛岃〃绀烘鏂囦欢瀵规墍鏈夌敤鎴烽兘鏄彲璇诲啓鐨勩 GiiModule
params CAttributeCollection 杩斿洖鐢ㄦ埛瀹氫箟鐨勫弬鏁般 CModule
parentModule CModule 杩斿洖鐖舵ā鍧椼 CModule
password string 鐢ㄤ簬璁块棶GiiModule鐨勫瘑鐮併 濡傛灉璁剧疆涓篺alse锛屽皢鍙互涓嶄娇鐢ㄥ瘑鐮佽闂瓽iiModule銆 (娉ㄦ剰锛氶櫎闈炰綘鏄庣‘鐭ラ亾鍚庢灉锛屽惁鍒欒涓嶈濡傛鍋!!!) GiiModule
preload array the IDs of the application components that should be preloaded. CModule
version string Returns the version of this module. CWebModule
viewPath string the root directory of view files. CWebModule

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() 鏋勯犳柟娉曘 CModule
__get() getter榄旀湳鏂规硶銆 CModule
__isset() 妫鏌ヤ竴涓睘鎬у兼槸鍚︿负null銆 CModule
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
afterControllerAction() The post-filter for controller actions. CWebModule
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
beforeControllerAction() 鎵ц瀵笹ii鐨勮闂鏌ャ GiiModule
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
configure() 涓烘ā鍧楁寚瀹氶厤缃 CModule
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getAssetsUrl() 杩斿洖鍖呭惈浜咷ii鐨勬墍鏈夎祫婧愭枃浠(asset files)鐨勫熀鍑哢RL銆 GiiModule
getBasePath() 杩斿洖妯″潡鏍圭洰褰曘 CModule
getComponent() Retrieves the named application component. CModule
getComponents() 杩斿洖搴旂敤缁勪欢銆 CModule
getControllerPath() 杩斿洖the directory that contains the controller classes. Defaults to 'moduleDir/controllers' where moduleDir is the directory containing the module class. CWebModule
getDescription() Returns the description of this module. CWebModule
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getId() 杩斿洖妯″潡ID銆 CModule
getLayoutPath() 杩斿洖the root directory of layout files. Defaults to 'moduleDir/views/layouts' where moduleDir is the directory containing the module class. CWebModule
getModule() 妫绱㈡寚瀹氱殑搴旂敤妯″潡銆 CModule
getModulePath() 杩斿洖鍖呭惈搴旂敤绋嬪簭妯″潡鐨勭洰褰曘 CModule
getModules() 杩斿洖搴旂敤绋嬪簭褰撳墠宸茬粡瀹夎鐨勬ā鍧椼 CModule
getName() Returns the name of this module. CWebModule
getParams() 杩斿洖鐢ㄦ埛瀹氫箟鐨勫弬鏁般 CModule
getParentModule() 杩斿洖鐖舵ā鍧椼 CModule
getVersion() Returns the version of this module. CWebModule
getViewPath() 杩斿洖the root directory of view files. Defaults to 'moduleDir/views' where moduleDir is the directory containing the module class. CWebModule
hasComponent() 妫鏌ユ槸鍚﹀瓨鍦ㄦ寚瀹氱粍浠躲 CModule
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasModule() 妫鏌ユ槸鍚﹀凡缁忓畨瑁呬簡鎸囧畾妯″潡銆 CModule
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
init() 鍒濆鍖杇ii妯″潡. GiiModule
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
setAliases() 瀹氫箟鏍圭洰褰曠殑鍒悕銆 CModule
setAssetsUrl() 璁剧疆鍖呭惈浜咷ii鐨勬墍鏈夎祫婧愭枃浠(asset files)鐨勫熀鍑哢RL銆 GiiModule
setBasePath() 璁剧疆鍧楁牴鐩綍銆 CModule
setComponent() 娣诲姞涓涓粍浠跺埌妯″潡涓 CModule
setComponents() 璁剧疆搴旂敤缁勪欢銆 CModule
setControllerPath() 璁剧疆the directory that contains the controller classes. CWebModule
setId() 璁剧疆妯″潡ID銆 CModule
setImport() 璁剧疆鍦ㄦā鍧椾腑浣跨敤鐨勮矾寰勫埆鍚嶃 CModule
setLayoutPath() 璁剧疆the root directory of layout files. CWebModule
setModulePath() 璁剧疆鍖呭惈搴旂敤绋嬪簭妯″潡鐨勭洰褰曘 CModule
setModules() 閰嶇疆妯″潡鐨勫瓙妯″潡銆 CModule
setParams() 璁剧疆鐢ㄦ埛瀹氫箟鐨勫弬鏁般 CModule
setViewPath() 璁剧疆the root directory of view files. CWebModule

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
allowIp() 妫鏌ョ敤鎴风殑鏉ユ簮IP鏄惁琚ipFilters鍏佽銆 GiiModule
findGenerators() 鏌ユ壘鎵鏈夊彲鐢ㄧ殑浠g爜鐢熸垚鍣ㄥ拰浠栦滑鐨勪唬鐮佹ā鏉裤 GiiModule
preinit() 妯″潡棰勫垵濮嬪寲銆 CModule
preloadComponents() 鍔犺浇闈欐佸簲鐢ㄧ粍浠躲 CModule

灞炴ц缁

assetsUrl 灞炴
public string getAssetsUrl()
public void setAssetsUrl(string $value)

鍖呭惈浜咷ii鐨勬墍鏈夎祫婧愭枃浠(asset files)鐨勫熀鍑哢RL銆

generatorPaths 灞炴
public array $generatorPaths;

涓涓矾寰勫埆鍚嶇殑鍒楄〃锛屽畠浠寚鍚戝寘鍚悇绉嶄唬鐮佺敓鎴愬櫒鐨 鐩綍銆備竴涓崟涓鐨勮矾寰勫埆鍚嶆寚鍚戠殑鐩綍鍙互鍖呭惈澶氫釜浠g爜鐢熸垚鍣紝姣 涓唬鐮佺敓鎴愬櫒瀛樻斁鍦ㄤ互鐢熸垚鍣ㄥ悕瀛楀懡鍚嶇殑瀛愮洰褰曚腑銆 榛樿鍊兼槸('application.gii')銆

ipFilters 灞炴
public array $ipFilters;

IP杩囨护鍣ㄧ殑鍒楄〃锛屾寚瀹氬摢浜汭P鍏佽璁块棶GiiModule銆 姣忎釜鏁扮粍鍏冪礌琛ㄨ揪涓涓崟涓鐨勮繃婊ゅ櫒銆備竴涓繃婊ゅ櫒鏃㈠彲浠ユ槸涓涓 IP鍦板潃锛屼篃鍙互鏄竴涓惈鏈夐氶厤绗︾殑鍦板潃锛堜緥濡傦細192.168.0.*锛夛紝 鍚庤呰〃绀轰竴涓綉娈点傚鏋滀綘甯屾湜鍏佽鎵鏈夌殑ID璁块棶GiiModule锛屼綘 闇瑕佸皢姝ゅ艰缃负false锛堥櫎闈炰綘鏄庣‘鍚庢灉鍚﹀垯璇峰埆杩欎箞鍋氾紒锛侊紒锛 榛樿鍊兼槸 array('127.0.0.1', '::1')锛岃〃绀哄彧鏈夋湰鍦颁富鏈烘墠鍙互 璁块棶GiiModule銆

newDirMode 灞炴
public integer $newDirMode;

涓烘柊鐢熸垚鐨勭洰褰曡缃殑鏉冮檺銆 杩欎釜鍊煎皢琚玃HPchmod鍑芥暟浣跨敤銆 榛樿鍊兼槸0777锛岃〃绀烘鏂囦欢瀵规墍鏈夌敤鎴烽兘鏄彲璇汇佸啓銆佹墽琛岀殑銆

newFileMode 灞炴
public integer $newFileMode;

涓烘柊鐢熸垚鐨勪唬鐮佹枃浠惰缃殑鏉冮檺銆 杩欎釜鍊煎皢琚玃HPchmod鍑芥暟浣跨敤銆 榛樿鍊兼槸0666锛岃〃绀烘鏂囦欢瀵规墍鏈夌敤鎴烽兘鏄彲璇诲啓鐨勩

password 灞炴
public string $password;

鐢ㄤ簬璁块棶GiiModule鐨勫瘑鐮併 濡傛灉璁剧疆涓篺alse锛屽皢鍙互涓嶄娇鐢ㄥ瘑鐮佽闂瓽iiModule銆 (娉ㄦ剰锛氶櫎闈炰綘鏄庣‘鐭ラ亾鍚庢灉锛屽惁鍒欒涓嶈濡傛鍋!!!)

鏂规硶璇︾粏

allowIp() 鏂规硶
protected boolean allowIp(string $ip)
$ip string 鐢ㄦ埛IP
{return} boolean 鐢ㄦ埛鐨勬潵婧怚P鏄惁琚ipFilters鍏佽銆
婧愮爜锛 framework/gii/GiiModule.php#184 (鏄剧ず)
protected function allowIp($ip)
{
    if(empty(
$this->ipFilters))
        return 
true;
    foreach(
$this->ipFilters as $filter)
    {
        if(
$filter==='*' || $filter===$ip || (($pos=strpos($filter,'*'))!==false && !strncmp($ip,$filter,$pos)))
            return 
true;
    }
    return 
false;
}

妫鏌ョ敤鎴风殑鏉ユ簮IP鏄惁琚ipFilters鍏佽銆

beforeControllerAction() 鏂规硶
public boolean beforeControllerAction(CController $controller, CAction $action)
$controller CController 闇瑕佽闂殑鎺у埗鍣ㄣ
$action CAction 闇瑕佽闂殑鍔ㄤ綔銆
{return} boolean 姝ゅ姩浣滄槸鍚﹀彲浠ユ墽琛屻
婧愮爜锛 framework/gii/GiiModule.php#159 (鏄剧ず)
public function beforeControllerAction($controller$action)
{
    if(
parent::beforeControllerAction($controller$action))
    {
        
$route=$controller->id.'/'.$action->id;
        if(!
$this->allowIp(Yii::app()->request->userHostAddress) && $route!=='default/error')
            throw new 
CHttpException(403,"You are not allowed to access this page.");

        
$publicPages=array(
            
'default/login',
            
'default/error',
        );
        if(
$this->password!==false && Yii::app()->user->isGuest && !in_array($route,$publicPages))
            
Yii::app()->user->loginRequired();
        else
            return 
true;
    }
    return 
false;
}

鎵ц瀵笹ii鐨勮闂鏌ャ 姝ゆ柟娉曞綋鐢ㄦ埛璁块棶闄や簡"default/login"鍜"default/error"涔嬪鐨勫姩浣滄椂锛 妫鏌ョ敤鎴风殑鏉ユ簮IP鍜屽瘑鐮佹槸鍚︽纭

findGenerators() 鏂规硶
protected array findGenerators()
{return} array
婧愮爜锛 framework/gii/GiiModule.php#200 (鏄剧ず)
protected function findGenerators()
{
    
$generators=array();
    
$n=count($this->generatorPaths);
    for(
$i=$n-1;$i>=0;--$i)
    {
        
$alias=$this->generatorPaths[$i];
        
$path=Yii::getPathOfAlias($alias);
        if(
$path===false || !is_dir($path))
            continue;

        
$names=scandir($path);
        foreach(
$names as $name)
        {
            if(
$name[0]!=='.' && is_dir($path.'/'.$name))
            {
                
$className=ucfirst($name).'Generator';
                if(
is_file("$path/$name/$className.php"))
                {
                    
$generators[$name]=array(
                        
'class'=>"$alias.$name.$className",
                    );
                }

                if(isset(
$generators[$name]) && is_dir("$path/$name/templates"))
                {
                    
$templatePath="$path/$name/templates";
                    
$dirs=scandir($templatePath);
                    foreach(
$dirs as $dir)
                    {
                        if(
$dir[0]!=='.' && is_dir($templatePath.'/'.$dir))
                            
$generators[$name]['templates'][$dir]=strtr($templatePath.'/'.$dir,array('/'=>DIRECTORY_SEPARATOR,'\\'=>DIRECTORY_SEPARATOR));
                    }
                }
            }
        }
    }
    return 
$generators;
}

鏌ユ壘鎵鏈夊彲鐢ㄧ殑浠g爜鐢熸垚鍣ㄥ拰浠栦滑鐨勪唬鐮佹ā鏉裤

getAssetsUrl() 鏂规硶
public string getAssetsUrl()
{return} string 鍖呭惈浜咷ii鐨勬墍鏈夎祫婧愭枃浠(asset files)鐨勫熀鍑哢RL銆
婧愮爜锛 framework/gii/GiiModule.php#136 (鏄剧ず)
public function getAssetsUrl()
{
    if(
$this->_assetsUrl===null)
        
$this->_assetsUrl=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('gii.assets'));
    return 
$this->_assetsUrl;
}

init() 鏂规硶
public void init()
婧愮爜锛 framework/gii/GiiModule.php#115 (鏄剧ず)
public function init()
{
    
parent::init();
    
Yii::app()->setComponents(array(
        
'errorHandler'=>array(
            
'class'=>'CErrorHandler',
            
'errorAction'=>$this->getId().'/default/error',
        ),
        
'user'=>array(
            
'class'=>'CWebUser',
            
'stateKeyPrefix'=>'gii',
            
'loginUrl'=>Yii::app()->createUrl($this->getId().'/default/login'),
        ),
    ), 
false);
    
$this->generatorPaths[]='gii.generators';
    
$this->controllerMap=$this->findGenerators();
}

鍒濆鍖杇ii妯″潡.

setAssetsUrl() 鏂规硶
public void setAssetsUrl(string $value)
$value string 鍖呭惈浜咷ii鐨勬墍鏈夎祫婧愭枃浠(asset files)鐨勫熀鍑哢RL銆
婧愮爜锛 framework/gii/GiiModule.php#146 (鏄剧ず)
public function setAssetsUrl($value)
{
    
$this->_assetsUrl=$value;
}

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