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 |
瑕佷娇鐢℅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 |
灞炴ц缁
鍖呭惈浜咷ii鐨勬墍鏈夎祫婧愭枃浠(asset files)鐨勫熀鍑哢RL銆
涓涓矾寰勫埆鍚嶇殑鍒楄〃锛屽畠浠寚鍚戝寘鍚悇绉嶄唬鐮佺敓鎴愬櫒鐨 鐩綍銆備竴涓崟涓鐨勮矾寰勫埆鍚嶆寚鍚戠殑鐩綍鍙互鍖呭惈澶氫釜浠g爜鐢熸垚鍣紝姣 涓唬鐮佺敓鎴愬櫒瀛樻斁鍦ㄤ互鐢熸垚鍣ㄥ悕瀛楀懡鍚嶇殑瀛愮洰褰曚腑銆 榛樿鍊兼槸('application.gii')銆
IP杩囨护鍣ㄧ殑鍒楄〃锛屾寚瀹氬摢浜汭P鍏佽璁块棶GiiModule銆 姣忎釜鏁扮粍鍏冪礌琛ㄨ揪涓涓崟涓鐨勮繃婊ゅ櫒銆備竴涓繃婊ゅ櫒鏃㈠彲浠ユ槸涓涓 IP鍦板潃锛屼篃鍙互鏄竴涓惈鏈夐氶厤绗︾殑鍦板潃锛堜緥濡傦細192.168.0.*锛夛紝 鍚庤呰〃绀轰竴涓綉娈点傚鏋滀綘甯屾湜鍏佽鎵鏈夌殑ID璁块棶GiiModule锛屼綘 闇瑕佸皢姝ゅ艰缃负false锛堥櫎闈炰綘鏄庣‘鍚庢灉鍚﹀垯璇峰埆杩欎箞鍋氾紒锛侊紒锛 榛樿鍊兼槸 array('127.0.0.1', '::1')锛岃〃绀哄彧鏈夋湰鍦颁富鏈烘墠鍙互 璁块棶GiiModule銆
涓烘柊鐢熸垚鐨勭洰褰曡缃殑鏉冮檺銆 杩欎釜鍊煎皢琚玃HPchmod鍑芥暟浣跨敤銆 榛樿鍊兼槸0777锛岃〃绀烘鏂囦欢瀵规墍鏈夌敤鎴烽兘鏄彲璇汇佸啓銆佹墽琛岀殑銆
涓烘柊鐢熸垚鐨勪唬鐮佹枃浠惰缃殑鏉冮檺銆 杩欎釜鍊煎皢琚玃HPchmod鍑芥暟浣跨敤銆 榛樿鍊兼槸0666锛岃〃绀烘鏂囦欢瀵规墍鏈夌敤鎴烽兘鏄彲璇诲啓鐨勩
鐢ㄤ簬璁块棶GiiModule鐨勫瘑鐮併 濡傛灉璁剧疆涓篺alse锛屽皢鍙互涓嶄娇鐢ㄥ瘑鐮佽闂瓽iiModule銆 (娉ㄦ剰锛氶櫎闈炰綘鏄庣‘鐭ラ亾鍚庢灉锛屽惁鍒欒涓嶈濡傛鍋!!!)
鏂规硶璇︾粏
protected boolean allowIp(string $ip)
| ||
$ip | string | 鐢ㄦ埛IP |
{return} | boolean | 鐢ㄦ埛鐨勬潵婧怚P鏄惁琚ipFilters鍏佽銆 |
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鍏佽銆
public boolean beforeControllerAction(CController $controller, CAction $action)
| ||
$controller | CController | 闇瑕佽闂殑鎺у埗鍣ㄣ |
$action | CAction | 闇瑕佽闂殑鍔ㄤ綔銆 |
{return} | boolean | 姝ゅ姩浣滄槸鍚﹀彲浠ユ墽琛屻 |
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鍜屽瘑鐮佹槸鍚︽纭
protected array findGenerators()
| ||
{return} | array |
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爜鐢熸垚鍣ㄥ拰浠栦滑鐨勪唬鐮佹ā鏉裤
public string getAssetsUrl()
| ||
{return} | string | 鍖呭惈浜咷ii鐨勬墍鏈夎祫婧愭枃浠(asset files)鐨勫熀鍑哢RL銆 |
public function getAssetsUrl()
{
if($this->_assetsUrl===null)
$this->_assetsUrl=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('gii.assets'));
return $this->_assetsUrl;
}
public void init()
|
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妯″潡.
public void setAssetsUrl(string $value)
| ||
$value | string | 鍖呭惈浜咷ii鐨勬墍鏈夎祫婧愭枃浠(asset files)鐨勫熀鍑哢RL銆 |
public function setAssetsUrl($value)
{
$this->_assetsUrl=$value;
}