PHP 클래스 yii\base\Theme

When View renders a view file, it will check the [[View::theme|active theme]] to see if there is a themed version of the view file exists. If so, the themed version will be rendered instead. A theme is a directory consisting of view files which are meant to replace their non-themed counterparts. Theme uses [[pathMap]] to achieve the view file replacement: 1. It first looks for a key in [[pathMap]] that is a substring of the given view file path; 2. If such a key exists, the corresponding value will be used to replace the corresponding part in the view file path; 3. It will then check if the updated view file exists or not. If so, that file will be used to replace the original view file. 4. If Step 2 or 3 fails, the original view file will be used. For example, if [[pathMap]] is ['@app/views' => '@app/themes/basic'], then the themed version for a view file @app/views/site/index.php will be @app/themes/basic/site/index.php. It is possible to map a single path to multiple paths. For example, ~~~ 'pathMap' => [ '@app/views' => [ '@app/themes/christmas', '@app/themes/basic', ], ] ~~~ In this case, the themed version could be either @app/themes/christmas/site/index.php or @app/themes/basic/site/index.php. The former has precedence over the latter if both files exist. To use a theme, you should configure the [[View::theme|theme]] property of the "view" application component like the following: ~~~ 'view' => [ 'theme' => [ 'basePath' => '@app/themes/basic', 'baseUrl' => '@web/themes/basic', ], ], ~~~ The above configuration specifies a theme located under the "themes/basic" directory of the Web folder that contains the entry script of the application. If your theme is designed to handle modules, you may configure the [[pathMap]] property like described above.
부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends Component
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$pathMap the mapping between view directories and their corresponding themed versions. This property is used by Theme::applyTo when a view is trying to apply the theme. Path aliases can be used when specifying directories. If this property is empty or not set, a mapping [[Application::basePath]] to [[basePath]] will be used.

공개 메소드들

메소드 설명
applyTo ( string $path ) : string Converts a file to a themed file if possible.
getBasePath ( ) : string
getBaseUrl ( ) : string
getPath ( string $path ) : string Converts a relative file path into an absolute one using [[basePath]].
getUrl ( string $url ) : string Converts a relative URL into an absolute URL using [[baseUrl]].
setBasePath ( string $path )
setBaseUrl ( string $url )

메소드 상세

applyTo() 공개 메소드

If there is no corresponding themed file, the original file will be returned.
public applyTo ( string $path ) : string
$path string the file to be themed
리턴 string the themed file, or the original file if the themed version is not available.

getBasePath() 공개 메소드

또한 보기: pathMap
public getBasePath ( ) : string
리턴 string the root path of this theme. All resources of this theme are located under this directory.

getBaseUrl() 공개 메소드

public getBaseUrl ( ) : string
리턴 string the base URL (without ending slash) for this theme. All resources of this theme are considered to be under this base URL.

getPath() 공개 메소드

Converts a relative file path into an absolute one using [[basePath]].
public getPath ( string $path ) : string
$path string the relative file path to be converted.
리턴 string the absolute file path

getUrl() 공개 메소드

Converts a relative URL into an absolute URL using [[baseUrl]].
public getUrl ( string $url ) : string
$url string the relative URL to be converted.
리턴 string the absolute URL

setBasePath() 공개 메소드

또한 보기: pathMap
public setBasePath ( string $path )
$path string the root path or path alias of this theme. All resources of this theme are located under this directory.

setBaseUrl() 공개 메소드

public setBaseUrl ( string $url )
$url string the base URL or path alias for this theme. All resources of this theme are considered to be under this base URL.

프로퍼티 상세

$pathMap 공개적으로 프로퍼티

the mapping between view directories and their corresponding themed versions. This property is used by Theme::applyTo when a view is trying to apply the theme. Path aliases can be used when specifying directories. If this property is empty or not set, a mapping [[Application::basePath]] to [[basePath]] will be used.
public $pathMap