CThemeManager

优质
小牛编辑
125浏览
2023-12-01
所有包 | 属性 | 方法
system.web
继承class CThemeManager » CApplicationComponent » CComponent
实现IApplicationComponent
源自1.0
版本$Id: CThemeManager.php 3426 2011-10-25 00:01:09Z alexander.makarow $
源码framework/web/CThemeManager.php
CThemeManager管理web应用程序的主题。

一个主题是一个view/layout文件和资源文件 (例如css,image,js文件)的集合。当一个主题是激活的时,CController 将首先在主题文件夹下查找指定的view/layout。 如果此主题提供了它们,相应的view/layout文件将被使用。 否则,默认的view/layout文件将被使用。

默认情况下,每一个主题被组织为一个目录,目录名就是主题名。 所有的主题存放在“WebRootPath/themes”目录下。

要激活一个主题,设置theme属性 为主题的名字。

一个独立的主题经常包含可经web访问的资源文件, 请确保view/layout文件被保护不被web用户访问。

公共属性

隐藏继承属性

属性类型描述定义在
basePathstring所有主题的基本路径。默认是“WebRootPath/themes”。CThemeManager
baseUrlstring所有主题的基本URL。默认是“/WebRoot/themes”。CThemeManager
behaviorsarray这个应用组件附加的行为。 这此行为将在应用组件调用init时附加在应用组件上。 请参照CModel::behaviors如何指定此属性值。CApplicationComponent
isInitializedboolean检查应用组件是否已经初始化。CApplicationComponent
themeClassstring表示一个主题的主题类名称。 默认是CTheme。这也可以是一个带点语法的类名。CThemeManager
themeNamesarray可用主题名列表CThemeManager

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__unset()设置一个组件的属性为null。CComponent
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
getBasePath()返回所有主题的基本路径。默认是“WebRootPath/themes”。CThemeManager
getBaseUrl()返回所有主题的基本URL。默认是“/WebRoot/themes”。CThemeManager
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getIsInitialized()检查应用组件是否已经初始化。CApplicationComponent
getTheme()返回已取回的主题。如果主题不存在为Null。CThemeManager
getThemeNames()返回可用主题名列表CThemeManager
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
init()初始化应用组件。CApplicationComponent
raiseEvent()发起一个事件。CComponent
setBasePath()设置所有主题基本路径。CThemeManager
setBaseUrl()设置所有主题的基本URL。CThemeManager

属性详细

basePath 属性 public string getBasePath()
public void setBasePath(string $value)

所有主题的基本路径。默认是“WebRootPath/themes”。

baseUrl 属性 public string getBaseUrl()
public void setBaseUrl(string $value)

所有主题的基本URL。默认是“/WebRoot/themes”。

themeClass 属性 public string $themeClass;

表示一个主题的主题类名称。 默认是CTheme。这也可以是一个带点语法的类名。

themeNames 属性 只读 public array getThemeNames()

可用主题名列表

方法详细

getBasePath() 方法
public string getBasePath()
{return}string所有主题的基本路径。默认是“WebRootPath/themes”。
源码: framework/web/CThemeManager.php#96 (显示) publicfunctiongetBasePath()
{
if($this->_basePath===null)
$this->setBasePath(dirname(Yii::app()->getRequest()->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH);
return$this->_basePath;
}
getBaseUrl() 方法
public string getBaseUrl()
{return}string所有主题的基本URL。默认是“/WebRoot/themes”。
源码: framework/web/CThemeManager.php#117 (显示) publicfunctiongetBaseUrl()
{
if($this->_baseUrl===null)
$this->_baseUrl=Yii::app()->getBaseUrl().'/'.self::DEFAULT_BASEPATH;
return$this->_baseUrl;
}
getTheme() 方法
public CTheme getTheme(string $name)
$namestring要取回的主题的名称
{return}CTheme已取回的主题。如果主题不存在为Null。
源码: framework/web/CThemeManager.php#59 (显示) publicfunctiongetTheme($name)
{
$themePath=$this->getBasePath().DIRECTORY_SEPARATOR.$name;
if(is_dir($themePath))
{
$class=Yii::import($this->themeClass,true);
returnnew$class($name,$themePath,$this->getBaseUrl().'/'.$name);
}
else
returnnull;
}
getThemeNames() 方法
public array getThemeNames()
{return}array可用主题名列表
源码: framework/web/CThemeManager.php#74 (显示) publicfunctiongetThemeNames()
{
static$themes;
if($themes===null)
{
$themes=array();
$basePath=$this->getBasePath();
$folder=@opendir($basePath);
while(($file=@readdir($folder))!==false)
{
if($file!=='.'&&$file!=='..'&&$file!=='.svn'&&is_dir($basePath.DIRECTORY_SEPARATOR.$file))
$themes[]=$file;
}
closedir($folder);
sort($themes);
}
return$themes;
}
setBasePath() 方法
public void setBasePath(string $value)
$valuestring所有主题基本路径。
源码: framework/web/CThemeManager.php#107 (显示) publicfunctionsetBasePath($value)
{
$this->_basePath=realpath($value);
if($this->_basePath===false||!is_dir($this->_basePath))
thrownewCException(Yii::t('yii','Themedirectory"{directory}"doesnotexist.',array('{directory}'=>$value)));
}
setBaseUrl() 方法
public void setBaseUrl(string $value)
$valuestring所有主题的基本URL。
源码: framework/web/CThemeManager.php#127 (显示) publicfunctionsetBaseUrl($value)
{
$this->_baseUrl=rtrim($value,'/');
}