CThemeManager
CThemeManager manages the themes for the Web application.
A theme is a collection of view/layout files and resource files (e.g. css, image, js files). When a theme is active,
CController will look for the specified view/layout under the theme folder first. The corresponding view/layout files will be used if the theme provides them. Otherwise, the default view/layout files will be used.
By default, each theme is organized as a directory whose name is the theme name. All themes are located under the "WebRootPath/themes" directory.
To activate a theme, set the
theme property to be the name of that theme.
Since a self-contained theme often contains resource files that are made Web accessible, please make sure the view/layout files are protected from Web access.
Public Properties
Property |
Type |
Description |
Defined By |
basePath | string | the base path for all themes. | CThemeManager |
baseUrl | string | the base URL for all themes. | CThemeManager |
behaviors | array | the behaviors that should be attached to this component. | CApplicationComponent |
isInitialized | boolean | Checks if this application component has been initialized. | CApplicationComponent |
themeClass | string | the name of the theme class for representing a theme. | CThemeManager |
themeNames | array | list of available theme names | CThemeManager |
Property Details
public string getBasePath()
public void setBasePath(string $value)
the base path for all themes. Defaults to "WebRootPath/themes".
public string getBaseUrl()
public void setBaseUrl(string $value)
the base URL for all themes. Defaults to "/WebRoot/themes".
public string $themeClass;
the name of the theme class for representing a theme. Defaults to CTheme. This can also be a class name in dot syntax.
public array getThemeNames()
list of available theme names
Method Details
public string getBasePath() |
{return} | string | the base path for all themes. Defaults to "WebRootPath/themes". |
Source Code: framework/web/CThemeManager.php#95 (
show)
public function getBasePath()
{
if($this->_basePath===null)
$this->setBasePath(dirname(Yii::app()->getRequest()->getScriptFile()).DIRECTORY_SEPARATOR.self::DEFAULT_BASEPATH);
return $this->_basePath;
}
public string getBaseUrl() |
{return} | string | the base URL for all themes. Defaults to "/WebRoot/themes". |
Source Code: framework/web/CThemeManager.php#116 (
show)
public function getBaseUrl()
{
if($this->_baseUrl===null)
$this->_baseUrl=Yii::app()->getBaseUrl().'/'.self::DEFAULT_BASEPATH;
return $this->_baseUrl;
}
public CTheme getTheme(string $name) |
$name | string | name of the theme to be retrieved |
{return} | CTheme | the theme retrieved. Null if the theme does not exist. |
Source Code: framework/web/CThemeManager.php#58 (
show)
public function getTheme($name)
{
$themePath=$this->getBasePath().DIRECTORY_SEPARATOR.$name;
if(is_dir($themePath))
{
$class=Yii::import($this->themeClass, true);
return new $class($name,$themePath,$this->getBaseUrl().'/'.$name);
}
else
return null;
}
public array getThemeNames() |
{return} | array | list of available theme names |
Source Code: framework/web/CThemeManager.php#73 (
show)
public function getThemeNames()
{
static $themes;
if($themes===null)
{
$themes=array();
$basePath=$this->getBasePath();
$folder=@opendir($basePath);
while(($file=@readdir($folder))!==false)
{
if($file!=='.' && $file!=='..' && $file!=='.svn' && $file!=='.gitignore' && is_dir($basePath.DIRECTORY_SEPARATOR.$file))
$themes[]=$file;
}
closedir($folder);
sort($themes);
}
return $themes;
}
public void setBasePath(string $value) |
$value | string | the base path for all themes. |
Source Code: framework/web/CThemeManager.php#106 (
show)
public function setBasePath($value)
{
$this->_basePath=realpath($value);
if($this->_basePath===false || !is_dir($this->_basePath))
throw new CException(Yii::t('yii','Theme directory "{directory}" does not exist.',array('{directory}'=>$value)));
}
public void setBaseUrl(string $value) |
$value | string | the base URL for all themes. |