PHP Class yii\web\View

View provides a set of methods (e.g. [[render()]]) for rendering purpose. View is configured as an application component in Application by default. You can access that instance via Yii::$app->view. You can modify its configuration by adding an array to your application config under components as it is shown in the following example: ~~~ 'view' => [ 'theme' => 'app\themes\MyTheme', 'renderers' => [ you may add Smarty or Twig renderer here ] ... ] ~~~
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\base\View
Show file Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$assetBundles list of the registered asset bundles. The keys are the bundle names, and the values are the registered AssetBundle objects.
$css the registered CSS code blocks.
$cssFiles the registered CSS files.
$js the registered JS code blocks
$jsFiles the registered JS files.
$linkTags the registered link tags.
$metaTags the registered meta tags.
$title the page title

Public Methods

Method Description
beginBody ( ) Marks the beginning of an HTML body section.
clear ( ) Clears up the registered meta tags, link tags, css/js scripts and files.
endBody ( ) Marks the ending of an HTML body section.
endPage ( boolean $ajaxMode = false ) Marks the ending of an HTML page.
getAssetManager ( ) : AssetManager Registers the asset manager being used by this view object.
head ( ) Marks the position of an HTML head section.
registerAssetBundle ( string $name, integer | null $position = null ) : AssetBundle Registers the named asset bundle.
registerCss ( string $css, array $options = [], string $key = null ) Registers a CSS code block.
registerCssFile ( string $url, array $options = [], string $key = null ) Registers a CSS file.
registerJs ( string $js, integer $position = self::POS_READY, string $key = null ) Registers a JS code block.
registerJsFile ( string $url, array $options = [], string $key = null ) Registers a JS file.
registerLinkTag ( array $options, string $key = null ) Registers a link tag.
registerMetaTag ( array $options, string $key = null ) Registers a meta tag.
renderAjax ( string $view, array $params = [], object $context = null ) : string Renders a view in response to an AJAX request.
setAssetManager ( AssetManager $value ) Sets the asset manager.

Protected Methods

Method Description
registerAssetFiles ( string $name ) Registers all files provided by an asset bundle including depending bundles files.
renderBodyBeginHtml ( ) : string Renders the content to be inserted at the beginning of the body section.
renderBodyEndHtml ( boolean $ajaxMode ) : string Renders the content to be inserted at the end of the body section.
renderHeadHtml ( ) : string Renders the content to be inserted in the head section.

Method Details

beginBody() public method

Marks the beginning of an HTML body section.
public beginBody ( )

clear() public method

Clears up the registered meta tags, link tags, css/js scripts and files.
public clear ( )

endBody() public method

Marks the ending of an HTML body section.
public endBody ( )

endPage() public method

Marks the ending of an HTML page.
public endPage ( boolean $ajaxMode = false )
$ajaxMode boolean whether the view is rendering in AJAX mode. If true, the JS scripts registered at [[POS_READY]] and [[POS_LOAD]] positions will be rendered at the end of the view like normal scripts.

getAssetManager() public method

Registers the asset manager being used by this view object.
public getAssetManager ( ) : AssetManager
return AssetManager the asset manager. Defaults to the "assetManager" application component.

head() public method

Marks the position of an HTML head section.
public head ( )

registerAssetBundle() public method

All dependent asset bundles will be registered.
public registerAssetBundle ( string $name, integer | null $position = null ) : AssetBundle
$name string the class name of the asset bundle (without the leading backslash)
$position integer | null if set, this forces a minimum position for javascript files. This will adjust depending assets javascript file position or fail if requirement can not be met. If this is null, asset bundles position settings will not be changed. See [[registerJsFile]] for more details on javascript position.
return AssetBundle the registered asset bundle instance

registerAssetFiles() protected method

Removes a bundle from [[assetBundles]] once files are registered.
protected registerAssetFiles ( string $name )
$name string name of the bundle to register

registerCss() public method

Registers a CSS code block.
public registerCss ( string $css, array $options = [], string $key = null )
$css string the content of the CSS code block to be registered
$options array the HTML attributes for the `