CViewRenderer
包 | system.web.renderers |
---|---|
继承 | abstract class CViewRenderer » CApplicationComponent » CComponent |
实现 | IApplicationComponent, IViewRenderer |
子类 | CPradoViewRenderer |
可用自 | 1.0 |
源码 | framework/web/renderers/CViewRenderer.php |
CViewRenderer is the base class for view renderer classes.
A view renderer is an application component that renders views written in a customized syntax.
Once installing a view renderer as a 'viewRenderer' application component, the normal view rendering process will be intercepted by the renderer. The renderer will first parse the source view file and then render the the resulting view file.
Parsing results are saved as temporary files that may be stored under the application runtime directory or together with the source view file.
A view renderer is an application component that renders views written in a customized syntax.
Once installing a view renderer as a 'viewRenderer' application component, the normal view rendering process will be intercepted by the renderer. The renderer will first parse the source view file and then render the the resulting view file.
Parsing results are saved as temporary files that may be stored under the application runtime directory or together with the source view file.
公共属性
属性 | 类型 | 描述 | 被定义在 |
---|---|---|---|
behaviors | array | the behaviors that should be attached to this component. | CApplicationComponent |
fileExtension | string | the extension name of the view file. | CViewRenderer |
filePermission | integer | the chmod permission for temporary directories and files generated during parsing. | CViewRenderer |
isInitialized | boolean | Checks if this application component has been initialized. | CApplicationComponent |
useRuntimePath | boolean | whether to store the parsing results in the application's runtime directory. | CViewRenderer |
公共方法
方法 | 描述 | 被定义在 |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
evaluateExpression() | Evaluates a PHP expression or callback under the context of this component. | CComponent |
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
getIsInitialized() | Checks if this application component has been initialized. | CApplicationComponent |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
init() | Initializes the application component. | CApplicationComponent |
raiseEvent() | Raises an event. | CComponent |
renderFile() | Renders a view file. | CViewRenderer |
受保护的方法
方法 | 描述 | 被定义在 |
---|---|---|
generateViewFile() | Parses the source view file and saves the results as another file. | CViewRenderer |
getViewFile() | Generates the resulting view file path. | CViewRenderer |
属性详情
fileExtension
属性
public string $fileExtension;
the extension name of the view file. Defaults to '.php'.
filePermission
属性
public integer $filePermission;
the chmod permission for temporary directories and files generated during parsing. Defaults to 0755 (owner rwx, group rx and others rx).
useRuntimePath
属性
public boolean $useRuntimePath;
whether to store the parsing results in the application's runtime directory. Defaults to true. If false, the parsing results will be saved as files under the same directory as the source view files and the file names will be the source file names appended with letter 'c'.
方法详情
generateViewFile()
方法
abstract protected void generateViewFile(string $sourceFile, string $viewFile)
| ||
$sourceFile | string | the source view file path |
$viewFile | string | the resulting view file path |
源码: framework/web/renderers/CViewRenderer.php#54 (显示)
abstract protected function generateViewFile($sourceFile,$viewFile);
Parses the source view file and saves the results as another file.
getViewFile()
方法
protected string getViewFile(string $file)
| ||
$file | string | source view file path |
{return} | string | resulting view file path |
源码: framework/web/renderers/CViewRenderer.php#84 (显示)
protected function getViewFile($file)
{
if($this->useRuntimePath)
{
$crc=sprintf('%x', crc32(get_class($this).Yii::getVersion().dirname($file)));
$viewFile=Yii::app()->getRuntimePath().DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.$crc.DIRECTORY_SEPARATOR.basename($file);
if(!is_file($viewFile))
@mkdir(dirname($viewFile),$this->filePermission,true);
return $viewFile;
}
else
return $file.'c';
}
Generates the resulting view file path.
renderFile()
方法
public mixed renderFile(CBaseController $context, string $sourceFile, mixed $data, boolean $return)
| ||
$context | CBaseController | the controller or widget who is rendering the view file. |
$sourceFile | string | the view file path |
$data | mixed | the data to be passed to the view |
$return | boolean | whether the rendering result should be returned |
{return} | mixed | the rendering result, or null if the rendering result is not needed. |
源码: framework/web/renderers/CViewRenderer.php#66 (显示)
public function renderFile($context,$sourceFile,$data,$return)
{
if(!is_file($sourceFile) || ($file=realpath($sourceFile))===false)
throw new CException(Yii::t('yii','View file "{file}" does not exist.',array('{file}'=>$sourceFile)));
$viewFile=$this->getViewFile($sourceFile);
if(@filemtime($sourceFile)>@filemtime($viewFile))
{
$this->generateViewFile($sourceFile,$viewFile);
@chmod($viewFile,$this->filePermission);
}
return $context->renderInternal($viewFile,$data,$return);
}
Renders a view file. This method is required by IViewRenderer.