View
extends View
in package
Class View
Tags
Table of Contents
Constants
- BLOCK_SIDEBAR = 'sidebar'
- the id of the sidebar block
- EVENT_AFTER_RENDER = 'afterRender'
- EVENT_BEFORE_RENDER = 'beforeRender'
- EVENT_BEGIN_BODY = 'beginBody'
- EVENT_BEGIN_PAGE = 'beginPage'
- EVENT_END_BODY = 'endBody'
- EVENT_END_PAGE = 'endPage'
- PH_BODY_BEGIN = '<![CDATA[YII-BLOCK-BODY-BEGIN]]>'
- This is internally used as the placeholder for receiving the content registered for the beginning of the body section.
- PH_BODY_END = '<![CDATA[YII-BLOCK-BODY-END]]>'
- This is internally used as the placeholder for receiving the content registered for the end of the body section.
- PH_HEAD = '<![CDATA[YII-BLOCK-HEAD]]>'
- This is internally used as the placeholder for receiving the content registered for the head section.
- POS_BEGIN = 2
- The location of registered JavaScript code block or files.
- POS_END = 3
- The location of registered JavaScript code block or files.
- POS_HEAD = 1
- The location of registered JavaScript code block or files.
- POS_LOAD = 5
- The location of registered JavaScript code block.
- POS_READY = 4
- The location of registered JavaScript code block.
Properties
- $assetBundles : array<string|int, AssetBundle>
- $assetManager : AssetManager
- $behaviors : array<string|int, Behavior>
- $blocks : array<string|int, mixed>
- $context : ViewContextInterface
- $css : array<string|int, mixed>
- $cssFiles : array<string|int, mixed>
- $defaultExtension : string
- $dynamicContents : array<string|int, DynamicContentAwareInterface>
- $js : array<string|int, mixed>
- $jsFiles : array<string|int, mixed>
- $linkTags : array<string|int, mixed>
- $meta : ViewMeta
- $metaTags : array<string|int, mixed>
- $pageTitle : string
- $params : array<string|int, mixed>
- $renderers : array<string|int, mixed>|null
- $scriptOptions : array<string|int, mixed>
- $sidebar : string
- $theme : Theme|array<string|int, mixed>|string|null
- $theme : Theme
- $title : string
- $viewContext : mixed
- $viewFile : string|bool
- $isPageEnded : bool
- Whether [[endPage()]] has been called and all files have been registered
- $preload : array<string|int, mixed>
- $_assetManager : mixed
- $_behaviors : array<string|int, Behavior>|null
- $_events : array<string|int, mixed>
- $_eventWildcards : array<string|int, mixed>
- $_pageTitle : string
- $_viewFiles : array<string|int, mixed>
- $_viewMeta : mixed
- $jsConfig : array<string|int, mixed>
- $preloaded : array<string|int, mixed>
- $viewContext : string
- A viewContext is a simple string value which usually is set by a controller to define the context of a resulting view.
Methods
- __call() : mixed
- Calls the named method which is not a class method.
- __clone() : mixed
- This method is called after the object is created by cloning an existing one.
- __construct() : mixed
- Constructor.
- __get() : mixed
- Returns the value of a component property.
- __isset() : bool
- Checks if a property is set, i.e. defined and not null.
- __set() : mixed
- Sets the value of a component property.
- __unset() : mixed
- Sets a component property to be null.
- addDynamicPlaceholder() : mixed
- Adds a placeholder for dynamic content.
- afterRender() : mixed
- This method is invoked right after [[renderFile()]] renders a view file.
- attachBehavior() : Behavior
- Attaches a behavior to this component.
- attachBehaviors() : mixed
- Attaches a list of behaviors to the component.
- beforeRender() : bool
- This method is invoked right before [[renderFile()]] renders a view file.
- beginBlock() : Block
- Begins recording a block.
- beginBody() : mixed
- Marks the beginning of an HTML body section.
- beginCache() : bool
- Begins fragment caching.
- beginContent() : ContentDecorator
- Begins the rendering of content that is to be decorated by the specified view.
- beginPage() : mixed
- Marks the beginning of a page.
- behaviors() : array<string|int, mixed>
- Returns a list of behaviors that this component should behave as.
- canGetProperty() : bool
- Returns a value indicating whether a property can be read.
- canSetProperty() : bool
- Returns a value indicating whether a property can be set.
- className() : string
- Returns the fully qualified name of this class.
- clear() : mixed
- Clears up the registered meta tags, link tags, css/js scripts and files.
- detachBehavior() : Behavior|null
- Detaches a behavior from the component.
- detachBehaviors() : mixed
- Detaches all behaviors from the component.
- endBlock() : mixed
- Ends recording a block.
- endBody() : mixed
- Marks the ending of an HTML body section.
- endCache() : mixed
- Ends fragment caching.
- endContent() : mixed
- Ends the rendering of content.
- endPage() : mixed
- Marks the ending of an HTML page.
- ensureBehaviors() : mixed
- Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.
- error() : mixed
- evaluateDynamicContent() : mixed
- Evaluates the given PHP statements.
- getAssetManager() : AssetManager
- Registers the asset manager being used by this view object.
- getBehavior() : Behavior|null
- Returns the named behavior object.
- getBehaviors() : array<string|int, Behavior>
- Returns all behaviors attached to this component.
- getDynamicContents() : array<string|int, DynamicContentAwareInterface>
- Returns a list of currently active dynamic content class instances.
- getDynamicPlaceholders() : array<string|int, mixed>
- Returns a list of placeholders for dynamic content. This method is used internally to implement the content caching feature.
- getMeta() : ViewMeta
- getPageTitle() : string
- Returns current page title
- getSidebar() : string
- Returns the sidebar which is stored in the block called 'sidebar'
- getViewFile() : string|bool
- hasEventHandlers() : bool
- Returns a value indicating whether there is any handler attached to the named event.
- hasMethod() : bool
- Returns a value indicating whether a method is defined.
- hasProperty() : bool
- Returns a value indicating whether a property is defined for this component.
- hasSidebar() : bool
- head() : mixed
- Marks the position of an HTML head section.
- info() : mixed
- init() : mixed
- Initializes the view component.
- off() : bool
- Detaches an existing event handler from this component.
- on() : mixed
- Attaches an event handler to an event.
- popDynamicContent() : mixed
- Removes a last class instance supporting dynamic contents from a list of currently active dynamic content class instances.
- pushDynamicContent() : mixed
- Adds a class instance supporting dynamic contents to the end of a list of currently active dynamic content class instances.
- registerAssetBundle() : AssetBundle
- Registers the named asset bundle.
- registerCsrfMetaTags() : mixed
- Registers CSRF meta tags.
- registerCss() : mixed
- Registers a CSS code block.
- registerCssFile() : mixed
- Registers a CSS file.
- registerJs() : mixed
- Registers a JS code block.
- registerJsConfig() : mixed
- Registers the javascript module configuration for one or multiple modules.
- registerJsFile() : mixed
- Registers a JS file.
- registerJsVar() : mixed
- Registers a JS code block defining a variable. The name of variable will be used as key, preventing duplicated variable names.
- registerLinkTag() : mixed
- Registers a link tag.
- registerMetaTag() : mixed
- Registers a meta tag.
- render() : string
- Renders a view.
- renderAjax() : string
- Renders a view in response to an AJAX request.
- renderAjaxContent() : string
- Renders a string as Ajax including assets.
- renderAjaxPartial() : string
- Renders a string as Ajax including assets without end page so it can be called several times.
- renderDynamic() : string
- Renders dynamic content returned by the given PHP statements.
- renderFile() : string
- Renders a view file.
- renderPhpFile() : string
- Renders a view file as a PHP script.
- saved() : mixed
- setAssetManager() : mixed
- Sets the asset manager.
- setDynamicPlaceholders() : mixed
- Sets a list of placeholders for dynamic content. This method is used internally to implement the content caching feature.
- setPageTitle() : mixed
- Sets current page title
- setStatusMessage() : mixed
- setViewContext() : mixed
- Sets the currently active viewContext.
- success() : mixed
- trigger() : mixed
- Triggers an event.
- warn() : mixed
- addCacheBustQuery() : string
- Adds cache bust query string to given url if no query is present
- findViewFile() : string
- Finds the view file based on the given view name.
- flushJsConfig() : mixed
- Writes the currently registered jsConfig entries and flushes the the config array.
- getRequestedViewFile() : string|bool
- registerAssetFiles() : mixed
- Registers all files provided by an asset bundle including depending bundles files.
- registerPreload() : mixed
- renderBodyBeginHtml() : string
- Renders the content to be inserted at the beginning of the body section.
- renderBodyEndHtml() : 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.
- attachBehaviorInternal() : Behavior
- Attaches a behavior to this component.
- registerFile() : mixed
- Registers a JS or CSS file.
- registerViewContext() : mixed
- Registers the client viewContext.
- renderEndPage() : mixed
- Render of ending page with all attached assets.
Constants
BLOCK_SIDEBAR
the id of the sidebar block
public
mixed
BLOCK_SIDEBAR
= 'sidebar'
EVENT_AFTER_RENDER
public
mixed
EVENT_AFTER_RENDER
= 'afterRender'
Tags
EVENT_BEFORE_RENDER
public
mixed
EVENT_BEFORE_RENDER
= 'beforeRender'
Tags
EVENT_BEGIN_BODY
public
mixed
EVENT_BEGIN_BODY
= 'beginBody'
Tags
EVENT_BEGIN_PAGE
public
mixed
EVENT_BEGIN_PAGE
= 'beginPage'
Tags
EVENT_END_BODY
public
mixed
EVENT_END_BODY
= 'endBody'
Tags
EVENT_END_PAGE
public
mixed
EVENT_END_PAGE
= 'endPage'
Tags
PH_BODY_BEGIN
This is internally used as the placeholder for receiving the content registered for the beginning of the body section.
public
mixed
PH_BODY_BEGIN
= '<![CDATA[YII-BLOCK-BODY-BEGIN]]>'
PH_BODY_END
This is internally used as the placeholder for receiving the content registered for the end of the body section.
public
mixed
PH_BODY_END
= '<![CDATA[YII-BLOCK-BODY-END]]>'
PH_HEAD
This is internally used as the placeholder for receiving the content registered for the head section.
public
mixed
PH_HEAD
= '<![CDATA[YII-BLOCK-HEAD]]>'
POS_BEGIN
The location of registered JavaScript code block or files.
public
mixed
POS_BEGIN
= 2
This means the location is at the beginning of the body section.
POS_END
The location of registered JavaScript code block or files.
public
mixed
POS_END
= 3
This means the location is at the end of the body section.
POS_HEAD
The location of registered JavaScript code block or files.
public
mixed
POS_HEAD
= 1
This means the location is in the head section.
POS_LOAD
The location of registered JavaScript code block.
public
mixed
POS_LOAD
= 5
This means the JavaScript code block will be enclosed within jQuery(window).load()
.
POS_READY
The location of registered JavaScript code block.
public
mixed
POS_READY
= 4
This means the JavaScript code block will be enclosed within jQuery(document).ready()
.
Properties
$assetBundles
public
array<string|int, AssetBundle>
$assetBundles
= []
list of the registered asset bundles. The keys are the bundle names, and the values are the registered [[AssetBundle]] objects.
Tags
$assetManager
public
AssetManager
$assetManager
The asset manager. Defaults to the "assetManager" application component.
$behaviors read-only
public
array<string|int, Behavior>
$behaviors
List of behaviors attached to this component.
$blocks
public
array<string|int, mixed>
$blocks
a list of named output blocks. The keys are the block names and the values are the corresponding block content. You can call [[beginBlock()]] and [[endBlock()]] to capture small fragments of a view. They can be later accessed somewhere else through this property.
$context
public
ViewContextInterface
$context
the context under which the [[renderFile()]] method is being invoked.
$css
public
array<string|int, mixed>
$css
= []
the registered CSS code blocks.
Tags
$cssFiles
public
array<string|int, mixed>
$cssFiles
= []
the registered CSS files.
Tags
$defaultExtension
public
string
$defaultExtension
= 'php'
the default view file extension. This will be appended to view file names if they don't have file extensions.
$dynamicContents read-only
public
array<string|int, DynamicContentAwareInterface>
$dynamicContents
Class instances supporting dynamic contents.
$js
public
array<string|int, mixed>
$js
= []
the registered JS code blocks
Tags
$jsFiles
public
array<string|int, mixed>
$jsFiles
= []
the registered JS files.
Tags
$linkTags
public
array<string|int, mixed>
$linkTags
= []
the registered link tags.
Tags
$meta
public
ViewMeta
$meta
The View Meta Service
$metaTags
public
array<string|int, mixed>
$metaTags
= []
the registered meta tags.
Tags
$pageTitle read-only
public
string
$pageTitle
$params
public
array<string|int, mixed>
$params
= []
custom parameters that are shared among view templates.
$renderers
public
array<string|int, mixed>|null
$renderers
a list of available renderers indexed by their corresponding supported file extensions. Each renderer may be a view renderer object or the configuration for creating the renderer object. For example, the following configuration enables both Smarty and Twig view renderers:
[
'tpl' => ['class' => 'yii\smarty\ViewRenderer'],
'twig' => ['class' => 'yii\twig\ViewRenderer'],
]
If no renderer is available for the given view file, the view file will be treated as a normal PHP and rendered via [[renderPhpFile()]].
$scriptOptions
public
array<string|int, mixed>
$scriptOptions
= []
the script tag options.
Tags
$sidebar read-only
public
string
$sidebar
$theme
public
Theme|array<string|int, mixed>|string|null
$theme
the theme object or the configuration for creating the theme object. If not set, it means theming is not enabled.
$theme
public
Theme
$theme
the Theme component
$title
public
string
$title
the page title
$viewContext write-only
public
mixed
$viewContext
$viewFile read-only
public
string|bool
$viewFile
The view file currently being rendered. False if no view file is being rendered.
$isPageEnded
Whether [[endPage()]] has been called and all files have been registered
protected
bool
$isPageEnded
= false
Tags
$preload
protected
static array<string|int, mixed>
$preload
= ['theme.css', 'bootstrap.css']
contains static core style and script assets which should be pre-loaded as <link rel="preload">
element.
$_assetManager
private
mixed
$_assetManager
$_behaviors
private
array<string|int, Behavior>|null
$_behaviors
the attached behaviors (behavior name => behavior). This is null
when not initialized.
$_events
private
array<string|int, mixed>
$_events
= []
the attached event handlers (event name => handlers)
$_eventWildcards
private
array<string|int, mixed>
$_eventWildcards
= []
the event handlers attached for wildcard patterns (event name wildcard => handlers)
Tags
$_pageTitle
private
string
$_pageTitle
page title
Tags
$_viewFiles
private
array<string|int, mixed>
$_viewFiles
= []
the view files currently being rendered. There may be multiple view files being rendered at a moment because one view may be rendered within another.
$_viewMeta
private
mixed
$_viewMeta
$jsConfig
private
array<string|int, mixed>
$jsConfig
= []
Contains javascript configurations, which will be appended to the view.
Tags
$preloaded
private
static array<string|int, mixed>
$preloaded
= []
contains already pre-loaded asset urls.
$viewContext
A viewContext is a simple string value which usually is set by a controller to define the context of a resulting view.
private
static string
$viewContext
If a viewContext is set, it will be sent to the client in case of pjax and full page loads. The HumHub Client API
will then use the viewContext in all ajax (non pjax) requests as HTTP request header HUMHUB-VIEW-CONTEXT
until the next pjax or full page load.
The viewContext is usually used to influence the view, e.g. a viewContext 'modal' indicates that the resulting view will be contained in a modal, a 'dashboard' context will indicate that the ajax request was sent from the dashboard.
A controller usually sets the viewContext within the init function e.g.:
public function init()
{
parent::init();
$this->view->setViewContext('dashboard');
}
Note: This variable won't contain the value of the request header but is only used to set the client viewContext.
Use Yii::$app->request->getViewContext()
to determine the active viewContext of a request.
defines a view context used in ajax requests
Tags
Methods
__call()
Calls the named method which is not a class method.
public
__call(string $name, array<string|int, mixed> $params) : mixed
This method will check if any attached behavior has the named method and will execute it if available.
Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.
Parameters
- $name : string
-
the method name
- $params : array<string|int, mixed>
-
method parameters
Tags
Return values
mixed —the method return value
__clone()
This method is called after the object is created by cloning an existing one.
public
__clone() : mixed
It removes all behaviors because they are attached to the old object.
__construct()
Constructor.
public
__construct([array<string|int, mixed> $config = [] ]) : mixed
The default implementation does two things:
- Initializes the object with the given configuration
$config
. - Call [[init()]].
If this method is overridden in a child class, it is recommended that
- the last parameter of the constructor is a configuration array, like
$config
here. - call the parent implementation at the end of the constructor.
Parameters
- $config : array<string|int, mixed> = []
-
name-value pairs that will be used to initialize the object properties
__get()
Returns the value of a component property.
public
__get(string $name) : mixed
This method will check in the following order and act accordingly:
- a property defined by a getter: return the getter result
- a property of a behavior: return the behavior property value
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing $value = $component->property;
.
Parameters
- $name : string
-
the property name
Tags
Return values
mixed —the property value or the value of a behavior's property
__isset()
Checks if a property is set, i.e. defined and not null.
public
__isset(string $name) : bool
This method will check in the following order and act accordingly:
- a property defined by a setter: return whether the property is set
- a property of a behavior: return whether the property is set
- return
false
for non existing properties
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing isset($component->property)
.
Parameters
- $name : string
-
the property name or the event name
Tags
Return values
bool —whether the named property is set
__set()
Sets the value of a component property.
public
__set(string $name, mixed $value) : mixed
This method will check in the following order and act accordingly:
- a property defined by a setter: set the property value
- an event in the format of "on xyz": attach the handler to the event "xyz"
- a behavior in the format of "as xyz": attach the behavior named as "xyz"
- a property of a behavior: set the behavior property value
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing $component->property = $value;
.
Parameters
- $name : string
-
the property name or the event name
- $value : mixed
-
the property value
Tags
__unset()
Sets a component property to be null.
public
__unset(string $name) : mixed
This method will check in the following order and act accordingly:
- a property defined by a setter: set the property value to be null
- a property of a behavior: set the property value to be null
Do not call this method directly as it is a PHP magic method that
will be implicitly called when executing unset($component->property)
.
Parameters
- $name : string
-
the property name
Tags
addDynamicPlaceholder()
Adds a placeholder for dynamic content.
public
addDynamicPlaceholder(mixed $placeholder, mixed $statements) : mixed
Parameters
- $placeholder : mixed
- $statements : mixed
-
the PHP statements for generating the dynamic content.
afterRender()
This method is invoked right after [[renderFile()]] renders a view file.
public
afterRender(string $viewFile, array<string|int, mixed> $params, string &$output) : mixed
The default implementation will trigger the [[EVENT_AFTER_RENDER]] event. If you override this method, make sure you call the parent implementation first.
Parameters
- $viewFile : string
-
the view file being rendered.
- $params : array<string|int, mixed>
-
the parameter array passed to the [[render()]] method.
- $output : string
-
the rendering result of the view file. Updates to this parameter will be passed back and returned by [[renderFile()]].
attachBehavior()
Attaches a behavior to this component.
public
attachBehavior(string $name, string|array<string|int, mixed>|Behavior $behavior) : Behavior
This method will create the behavior object based on the given configuration. After that, the behavior object will be attached to this component by calling the [[Behavior::attach()]] method.
Parameters
- $name : string
-
the name of the behavior.
- $behavior : string|array<string|int, mixed>|Behavior
-
the behavior configuration. This can be one of the following:
- a [[Behavior]] object
- a string specifying the behavior class
- an object configuration array that will be passed to [[Yii::createObject()]] to create the behavior object.
Tags
Return values
Behavior —the behavior object
attachBehaviors()
Attaches a list of behaviors to the component.
public
attachBehaviors(array<string|int, mixed> $behaviors) : mixed
Each behavior is indexed by its name and should be a [[Behavior]] object, a string specifying the behavior class, or an configuration array for creating the behavior.
Parameters
- $behaviors : array<string|int, mixed>
-
list of behaviors to be attached to the component
Tags
beforeRender()
This method is invoked right before [[renderFile()]] renders a view file.
public
beforeRender(string $viewFile, array<string|int, mixed> $params) : bool
The default implementation will trigger the [[EVENT_BEFORE_RENDER]] event. If you override this method, make sure you call the parent implementation first.
Parameters
- $viewFile : string
-
the view file to be rendered.
- $params : array<string|int, mixed>
-
the parameter array passed to the [[render()]] method.
Return values
bool —whether to continue rendering the view file.
beginBlock()
Begins recording a block.
public
beginBlock(string $id[, bool $renderInPlace = false ]) : Block
This method is a shortcut to beginning [[Block]].
Parameters
- $id : string
-
the block ID.
- $renderInPlace : bool = false
-
whether to render the block content in place. Defaults to false, meaning the captured block will not be displayed.
Return values
Block —the Block widget instance
beginBody()
Marks the beginning of an HTML body section.
public
beginBody() : mixed
beginCache()
Begins fragment caching.
public
beginCache(string $id[, array<string|int, mixed> $properties = [] ]) : bool
This method will display cached content if it is available. If not, it will start caching and would expect an [[endCache()]] call to end the cache and save the content into cache. A typical usage of fragment caching is as follows,
if ($this->beginCache($id)) {
// ...generate content here
$this->endCache();
}
Parameters
- $id : string
-
a unique ID identifying the fragment to be cached.
- $properties : array<string|int, mixed> = []
-
initial property values for [[FragmentCache]]
Return values
bool —whether you should generate the content for caching. False if the cached version is available.
beginContent()
Begins the rendering of content that is to be decorated by the specified view.
public
beginContent(string $viewFile[, array<string|int, mixed> $params = [] ]) : ContentDecorator
This method can be used to implement nested layout. For example, a layout can be embedded in another layout file specified as '@app/views/layouts/base.php' like the following:
<?php $this->beginContent('@app/views/layouts/base.php'); ?>
//...layout content here...
<?php $this->endContent(); ?>
Parameters
- $viewFile : string
-
the view file that will be used to decorate the content enclosed by this widget. This can be specified as either the view file path or path alias.
- $params : array<string|int, mixed> = []
-
the variables (name => value) to be extracted and made available in the decorative view.
Tags
Return values
ContentDecorator —the ContentDecorator widget instance
beginPage()
Marks the beginning of a page.
public
beginPage() : mixed
behaviors()
Returns a list of behaviors that this component should behave as.
public
behaviors() : array<string|int, mixed>
Child classes may override this method to specify the behaviors they want to behave as.
The return value of this method should be an array of behavior objects or configurations indexed by behavior names. A behavior configuration can be either a string specifying the behavior class or an array of the following structure:
'behaviorName' => [
'class' => 'BehaviorClass',
'property1' => 'value1',
'property2' => 'value2',
]
Note that a behavior class must extend from [[Behavior]]. Behaviors can be attached using a name or anonymously. When a name is used as the array key, using this name, the behavior can later be retrieved using [[getBehavior()]] or be detached using [[detachBehavior()]]. Anonymous behaviors can not be retrieved or detached.
Behaviors declared in this method will be attached to the component automatically (on demand).
Return values
array<string|int, mixed> —the behavior configurations.
canGetProperty()
Returns a value indicating whether a property can be read.
public
canGetProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool
A property can be read if:
- the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true); - an attached behavior has a readable property of the given name (when
$checkBehaviors
is true).
Parameters
- $name : string
-
the property name
- $checkVars : bool = true
-
whether to treat member variables as properties
- $checkBehaviors : bool = true
-
whether to treat behaviors' properties as properties of this component
Tags
Return values
bool —whether the property can be read
canSetProperty()
Returns a value indicating whether a property can be set.
public
canSetProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool
A property can be written if:
- the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true); - an attached behavior has a writable property of the given name (when
$checkBehaviors
is true).
Parameters
- $name : string
-
the property name
- $checkVars : bool = true
-
whether to treat member variables as properties
- $checkBehaviors : bool = true
-
whether to treat behaviors' properties as properties of this component
Tags
Return values
bool —whether the property can be written
className()
Returns the fully qualified name of this class.
public
static className() : string
Tags
Return values
string —the fully qualified name of this class.
clear()
Clears up the registered meta tags, link tags, css/js scripts and files.
public
clear() : mixed
detachBehavior()
Detaches a behavior from the component.
public
detachBehavior(string $name) : Behavior|null
The behavior's [[Behavior::detach()]] method will be invoked.
Parameters
- $name : string
-
the behavior's name.
Return values
Behavior|null —the detached behavior. Null if the behavior does not exist.
detachBehaviors()
Detaches all behaviors from the component.
public
detachBehaviors() : mixed
endBlock()
Ends recording a block.
public
endBlock() : mixed
endBody()
Marks the ending of an HTML body section.
public
endBody() : mixed
Tags
endCache()
Ends fragment caching.
public
endCache() : mixed
endContent()
Ends the rendering of content.
public
endContent() : mixed
endPage()
Marks the ending of an HTML page.
public
endPage([bool $ajaxMode = false ]) : mixed
Parameters
- $ajaxMode : bool = false
-
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.
ensureBehaviors()
Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.
public
ensureBehaviors() : mixed
error()
public
error(mixed $message) : mixed
Parameters
- $message : mixed
evaluateDynamicContent()
Evaluates the given PHP statements.
public
evaluateDynamicContent(string $statements) : mixed
This method is mainly used internally to implement dynamic content feature.
Parameters
- $statements : string
-
the PHP statements to be evaluated.
Return values
mixed —the return value of the PHP statements.
getAssetManager()
Registers the asset manager being used by this view object.
public
getAssetManager() : AssetManager
Return values
AssetManager —the asset manager. Defaults to the "assetManager" application component.
getBehavior()
Returns the named behavior object.
public
getBehavior(string $name) : Behavior|null
Parameters
- $name : string
-
the behavior name
Return values
Behavior|null —the behavior object, or null if the behavior does not exist
getBehaviors()
Returns all behaviors attached to this component.
public
getBehaviors() : array<string|int, Behavior>
Return values
array<string|int, Behavior> —list of behaviors attached to this component
getDynamicContents()
Returns a list of currently active dynamic content class instances.
public
getDynamicContents() : array<string|int, DynamicContentAwareInterface>
Tags
Return values
array<string|int, DynamicContentAwareInterface> —class instances supporting dynamic contents.
getDynamicPlaceholders()
Returns a list of placeholders for dynamic content. This method is used internally to implement the content caching feature.
public
getDynamicPlaceholders() : array<string|int, mixed>
Return values
array<string|int, mixed> —a list of placeholders.
getMeta()
public
getMeta() : ViewMeta
Return values
ViewMetagetPageTitle()
Returns current page title
public
getPageTitle() : string
Return values
string —the page title
getSidebar()
Returns the sidebar which is stored in the block called 'sidebar'
public
getSidebar() : string
Return values
string —returns the rendered sidebar
getViewFile()
public
getViewFile() : string|bool
Return values
string|bool —the view file currently being rendered. False if no view file is being rendered.
hasEventHandlers()
Returns a value indicating whether there is any handler attached to the named event.
public
hasEventHandlers(string $name) : bool
Parameters
- $name : string
-
the event name
Return values
bool —whether there is any handler attached to the event.
hasMethod()
Returns a value indicating whether a method is defined.
public
hasMethod(string $name[, bool $checkBehaviors = true ]) : bool
A method is defined if:
- the class has a method with the specified name
- an attached behavior has a method with the given name (when
$checkBehaviors
is true).
Parameters
- $name : string
-
the property name
- $checkBehaviors : bool = true
-
whether to treat behaviors' methods as methods of this component
Return values
bool —whether the method is defined
hasProperty()
Returns a value indicating whether a property is defined for this component.
public
hasProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool
A property is defined if:
- the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true); - an attached behavior has a property of the given name (when
$checkBehaviors
is true).
Parameters
- $name : string
-
the property name
- $checkVars : bool = true
-
whether to treat member variables as properties
- $checkBehaviors : bool = true
-
whether to treat behaviors' properties as properties of this component
Tags
Return values
bool —whether the property is defined
hasSidebar()
public
hasSidebar() : bool
Return values
bool —checks if a sidebar exists
head()
Marks the position of an HTML head section.
public
head() : mixed
info()
public
info(mixed $message) : mixed
Parameters
- $message : mixed
init()
Initializes the view component.
public
init() : mixed
off()
Detaches an existing event handler from this component.
public
off(string $name[, callable|null $handler = null ]) : bool
This method is the opposite of [[on()]].
Note: in case wildcard pattern is passed for event name, only the handlers registered with this wildcard will be removed, while handlers registered with plain names matching this wildcard will remain.
Parameters
- $name : string
-
event name
- $handler : callable|null = null
-
the event handler to be removed. If it is null, all handlers attached to the named event will be removed.
Tags
Return values
bool —if a handler is found and detached
on()
Attaches an event handler to an event.
public
on(string $name, callable $handler[, mixed $data = null ][, bool $append = true ]) : mixed
The event handler must be a valid PHP callback. The following are some examples:
function ($event) { ... } // anonymous function
[$object, 'handleClick'] // $object->handleClick()
['Page', 'handleClick'] // Page::handleClick()
'handleClick' // global function handleClick()
The event handler must be defined with the following signature,
function ($event)
where $event
is an [[Event]] object which includes parameters associated with the event.
Since 2.0.14 you can specify event name as a wildcard pattern:
$component->on('event.group.*', function ($event) {
Yii::trace($event->name . ' is triggered.');
});
Parameters
- $name : string
-
the event name
- $handler : callable
-
the event handler
- $data : mixed = null
-
the data to be passed to the event handler when the event is triggered. When the event handler is invoked, this data can be accessed via [[Event::data]].
- $append : bool = true
-
whether to append new event handler to the end of the existing handler list. If false, the new handler will be inserted at the beginning of the existing handler list.
Tags
popDynamicContent()
Removes a last class instance supporting dynamic contents from a list of currently active dynamic content class instances.
public
popDynamicContent() : mixed
Tags
pushDynamicContent()
Adds a class instance supporting dynamic contents to the end of a list of currently active dynamic content class instances.
public
pushDynamicContent(DynamicContentAwareInterface $instance) : mixed
Parameters
- $instance : DynamicContentAwareInterface
-
class instance supporting dynamic contents.
Tags
registerAssetBundle()
Registers the named asset bundle.
public
registerAssetBundle(mixed $name[, mixed $position = null ]) : AssetBundle
Parameters
- $name : mixed
-
the class name of the asset bundle (without the leading backslash)
- $position : mixed = 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.
Tags
Return values
AssetBundle —the registered asset bundle instance
registerCsrfMetaTags()
Registers CSRF meta tags.
public
registerCsrfMetaTags() : mixed
They are rendered dynamically to retrieve a new CSRF token for each request.
$view->registerCsrfMetaTags();
The above code will result in <meta name="csrf-param" content="[yii\web\Request::$csrfParam]">
and <meta name="csrf-token" content="tTNpWKpdy-bx8ZmIq9R72...K1y8IP3XGkzZA==">
added to the page.
Note: Hidden CSRF input of ActiveForm will be automatically refreshed by calling window.yii.refreshCsrfToken()
from yii.js
.
Tags
registerCss()
Registers a CSS code block.
public
registerCss(string $css[, array<string|int, mixed> $options = [] ][, string|null $key = null ]) : mixed
Parameters
- $css : string
-
the content of the CSS code block to be registered
- $options : array<string|int, mixed> = []
-
the HTML attributes for the
<style>
-tag. - $key : string|null = null
-
the key that identifies the CSS code block. If null, it will use $css as the key. If two CSS code blocks are registered with the same key, the latter will overwrite the former.
registerCssFile()
Registers a CSS file.
public
registerCssFile(mixed $url[, mixed $options = [] ][, mixed $key = null ]) : mixed
Parameters
- $url : mixed
-
the CSS file to be registered.
- $options : mixed = []
-
the HTML attributes for the link tag. Please refer to [[Html::cssFile()]] for the supported options. The following options are specially handled and are not treated as HTML attributes:
-
depends
: array, specifies the names of the asset bundles that this CSS file depends on. -
appendTimestamp
: bool whether to append a timestamp to the URL.
-
- $key : mixed = null
-
the key that identifies the CSS script file. If null, it will use $url as the key. If two CSS files are registered with the same key, the latter will overwrite the former.
Tags
registerJs()
Registers a JS code block.
public
registerJs(string $js[, int $position = self::POS_READY ][, string|null $key = null ]) : mixed
Parameters
- $js : string
-
the JS code block to be registered
- $position : int = self::POS_READY
-
the position at which the JS script tag should be inserted in a page. The possible values are:
- [[POS_HEAD]]: in the head section
- [[POS_BEGIN]]: at the beginning of the body section
- [[POS_END]]: at the end of the body section
- [[POS_LOAD]]: enclosed within jQuery(window).load(). Note that by using this position, the method will automatically register the jQuery js file.
- [[POS_READY]]: enclosed within jQuery(document).ready(). This is the default value. Note that by using this position, the method will automatically register the jQuery js file.
- $key : string|null = null
-
the key that identifies the JS code block. If null, it will use $js as the key. If two JS code blocks are registered with the same key, the latter will overwrite the former.
registerJsConfig()
Registers the javascript module configuration for one or multiple modules.
public
registerJsConfig(mixed $module[, null $params = null ]) : mixed
$this->registerJsConfig('moduleId', [
'someKey' => 'someValue'
]);
// or
$this->registerJsConfig([
'module1' => [
'someKey' => 'someValue'
],
'module2' => [
'someKey' => 'anotherValue';
]
]);
Parameters
- $module : mixed
- $params : null = null
registerJsFile()
Registers a JS file.
public
registerJsFile(mixed $url[, mixed $options = [] ][, mixed $key = null ]) : mixed
Parameters
- $url : mixed
-
the JS file to be registered.
- $options : mixed = []
-
the HTML attributes for the script tag. The following options are specially handled and are not treated as HTML attributes:
-
depends
: array, specifies the names of the asset bundles that this JS file depends on. -
position
: specifies where the JS script tag should be inserted in a page. The possible values are:-
- [[POS_HEAD]]: in the head section
-
- [[POS_BEGIN]]: at the beginning of the body section
-
- [[POS_END]]: at the end of the body section. This is the default value.
-
-
appendTimestamp
: bool whether to append a timestamp to the URL.
Please refer to [[Html::jsFile()]] for other supported options.
-
- $key : mixed = null
-
the key that identifies the JS script file. If null, it will use $url as the key. If two JS files are registered with the same key at the same position, the latter will overwrite the former. Note that position option takes precedence, thus files registered with the same key, but different position option will not override each other.
Tags
registerJsVar()
Registers a JS code block defining a variable. The name of variable will be used as key, preventing duplicated variable names.
public
registerJsVar(string $name, array<string|int, mixed>|string $value[, int $position = self::POS_HEAD ]) : mixed
Parameters
- $name : string
-
Name of the variable
- $value : array<string|int, mixed>|string
-
Value of the variable
- $position : int = self::POS_HEAD
-
the position in a page at which the JavaScript variable should be inserted. The possible values are:
- [[POS_HEAD]]: in the head section. This is the default value.
- [[POS_BEGIN]]: at the beginning of the body section.
- [[POS_END]]: at the end of the body section.
- [[POS_LOAD]]: enclosed within jQuery(window).load(). Note that by using this position, the method will automatically register the jQuery js file.
- [[POS_READY]]: enclosed within jQuery(document).ready(). Note that by using this position, the method will automatically register the jQuery js file.
Tags
registerLinkTag()
Registers a link tag.
public
registerLinkTag(array<string|int, mixed> $options[, string|null $key = null ]) : mixed
For example, a link tag for a custom favicon can be added like the following:
$view->registerLinkTag(['rel' => 'icon', 'type' => 'image/png', 'href' => '/myicon.png']);
which will result in the following HTML: <link rel="icon" type="image/png" href="/myicon.png">
.
Note: To register link tags for CSS stylesheets, use [[registerCssFile()]] instead, which has more options for this kind of link tag.
Parameters
- $options : array<string|int, mixed>
-
the HTML attributes for the link tag.
- $key : string|null = null
-
the key that identifies the link tag. If two link tags are registered with the same key, the latter will overwrite the former. If this is null, the new link tag will be appended to the existing ones.
registerMetaTag()
Registers a meta tag.
public
registerMetaTag(array<string|int, mixed> $options[, string|null $key = null ]) : mixed
For example, a description meta tag can be added like the following:
$view->registerMetaTag([
'name' => 'description',
'content' => 'This website is about funny raccoons.'
]);
will result in the meta tag <meta name="description" content="This website is about funny raccoons.">
.
Parameters
- $options : array<string|int, mixed>
-
the HTML attributes for the meta tag.
- $key : string|null = null
-
the key that identifies the meta tag. If two meta tags are registered with the same key, the latter will overwrite the former. If this is null, the new meta tag will be appended to the existing ones.
render()
Renders a view.
public
render(string $view[, array<string|int, mixed> $params = [] ][, object|null $context = null ]) : string
The view to be rendered can be specified in one of the following formats:
- path alias (e.g. "@app/views/site/index");
- absolute path within application (e.g. "//site/index"): the view name starts with double slashes. The actual view file will be looked for under the [[Application::viewPath|view path]] of the application.
- absolute path within current module (e.g. "/site/index"): the view name starts with a single slash. The actual view file will be looked for under the [[Module::viewPath|view path]] of the [[Controller::module|current module]].
- relative view (e.g. "index"): the view name does not start with
@
or/
. The corresponding view file will be looked for under the [[ViewContextInterface::getViewPath()|view path]] of the view$context
. If$context
is not given, it will be looked for under the directory containing the view currently being rendered (i.e., this happens when rendering a view within another view).
Parameters
- $view : string
-
the view name.
- $params : array<string|int, mixed> = []
-
the parameters (name-value pairs) that will be extracted and made available in the view file.
- $context : object|null = null
-
the context to be assigned to the view and can later be accessed via [[context]] in the view. If the context implements [[ViewContextInterface]], it may also be used to locate the view file corresponding to a relative view name.
Tags
Return values
string —the rendering result
renderAjax()
Renders a view in response to an AJAX request.
public
renderAjax(mixed $view[, mixed $params = [] ][, mixed $context = null ]) : string
Parameters
- $view : mixed
-
the view name. Please refer to [[render()]] on how to specify this parameter.
- $params : mixed = []
-
the parameters (name-value pairs) that will be extracted and made available in the view file.
- $context : mixed = null
-
the context that the view should use for rendering the view. If null, existing [[context]] will be used.
Tags
Return values
string —the rendering result
renderAjaxContent()
Renders a string as Ajax including assets.
public
renderAjaxContent(string $content) : string
Parameters
- $content : string
Return values
string —Rendered content
renderAjaxPartial()
Renders a string as Ajax including assets without end page so it can be called several times.
public
renderAjaxPartial(string $content) : string
Parameters
- $content : string
Return values
string —Rendered content
renderDynamic()
Renders dynamic content returned by the given PHP statements.
public
renderDynamic(string $statements) : string
This method is mainly used together with content caching (fragment caching and page caching) when some portions of the content (called dynamic content) should not be cached. The dynamic content must be returned by some PHP statements.
Parameters
- $statements : string
-
the PHP statements for generating the dynamic content.
Tags
Return values
string —the placeholder of the dynamic content, or the dynamic content if there is no active content cache currently.
Note that most methods that indirectly modify layout such as registerJS() or registerJSFile() do not work with dynamic rendering.
renderFile()
Renders a view file.
public
renderFile(string $viewFile[, array<string|int, mixed> $params = [] ][, object|null $context = null ]) : string
If [[theme]] is enabled (not null), it will try to render the themed version of the view file as long as it is available.
The method will call [[FileHelper::localize()]] to localize the view file.
If [[renderers|renderer]] is enabled (not null), the method will use it to render the view file. Otherwise, it will simply include the view file as a normal PHP file, capture its output and return it as a string.
Parameters
- $viewFile : string
-
the view file. This can be either an absolute file path or an alias of it.
- $params : array<string|int, mixed> = []
-
the parameters (name-value pairs) that will be extracted and made available in the view file.
- $context : object|null = null
-
the context that the view should use for rendering the view. If null, existing [[context]] will be used.
Tags
Return values
string —the rendering result
renderPhpFile()
Renders a view file as a PHP script.
public
renderPhpFile(string $_file_[, array<string|int, mixed> $_params_ = [] ]) : string
This method treats the view file as a PHP script and includes the file. It extracts the given parameters and makes them available in the view file. The method captures the output of the included view file and returns it as a string.
This method should mainly be called by view renderer or [[renderFile()]].
Parameters
- $_file_ : string
-
the view file.
- $_params_ : array<string|int, mixed> = []
-
the parameters (name-value pairs) that will be extracted and made available in the view file.
Tags
Return values
string —the rendering result
saved()
public
saved() : mixed
setAssetManager()
Sets the asset manager.
public
setAssetManager(AssetManager $value) : mixed
Parameters
- $value : AssetManager
-
the asset manager
setDynamicPlaceholders()
Sets a list of placeholders for dynamic content. This method is used internally to implement the content caching feature.
public
setDynamicPlaceholders(mixed $placeholders) : mixed
Parameters
- $placeholders : mixed
-
a list of placeholders.
setPageTitle()
Sets current page title
public
setPageTitle(string $title[, bool $prepend = false ]) : mixed
Parameters
- $title : string
- $prepend : bool = false
setStatusMessage()
public
setStatusMessage(mixed $type, mixed $message) : mixed
Parameters
- $type : mixed
- $message : mixed
setViewContext()
Sets the currently active viewContext.
public
setViewContext(mixed $vctx) : mixed
Parameters
- $vctx : mixed
Tags
success()
public
success(mixed $message) : mixed
Parameters
- $message : mixed
trigger()
Triggers an event.
public
trigger(string $name[, Event|null $event = null ]) : mixed
This method represents the happening of an event. It invokes all attached handlers for the event including class-level handlers.
Parameters
- $name : string
-
the event name
- $event : Event|null = null
-
the event instance. If not set, a default [[Event]] object will be created.
warn()
public
warn(mixed $message) : mixed
Parameters
- $message : mixed
addCacheBustQuery()
Adds cache bust query string to given url if no query is present
protected
addCacheBustQuery(string $url) : string
Parameters
- $url : string
Return values
string —the URL with cache bust paramter
findViewFile()
Finds the view file based on the given view name.
protected
findViewFile(string $view[, object|null $context = null ]) : string
Parameters
- $view : string
-
the view name or the path alias of the view file. Please refer to [[render()]] on how to specify this parameter.
- $context : object|null = null
-
the context to be assigned to the view and can later be accessed via [[context]] in the view. If the context implements [[ViewContextInterface]], it may also be used to locate the view file corresponding to a relative view name.
Tags
Return values
string —the view file path. Note that the file may not exist.
flushJsConfig()
Writes the currently registered jsConfig entries and flushes the the config array.
protected
flushJsConfig([string $key = null ]) : mixed
Parameters
- $key : string = null
-
see View::registerJs
Tags
getRequestedViewFile()
protected
getRequestedViewFile() : string|bool
Tags
Return values
string|bool —the requested view currently being rendered. False if no view file is being rendered.
registerAssetFiles()
Registers all files provided by an asset bundle including depending bundles files.
protected
registerAssetFiles(mixed $name) : mixed
Removes a bundle from [[assetBundles]] once files are registered.
Parameters
- $name : mixed
-
name of the bundle to register
registerPreload()
protected
registerPreload(mixed $url, mixed $as) : mixed
Parameters
- $url : mixed
- $as : mixed
renderBodyBeginHtml()
Renders the content to be inserted at the beginning of the body section.
protected
renderBodyBeginHtml() : string
Tags
Return values
string —the rendered content
renderBodyEndHtml()
Renders the content to be inserted at the end of the body section.
protected
renderBodyEndHtml(mixed $ajaxMode) : string
Parameters
- $ajaxMode : mixed
-
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.
Tags
Return values
string —the rendered content
renderHeadHtml()
Renders the content to be inserted in the head section.
protected
renderHeadHtml() : string
Tags
Return values
string —the rendered content
attachBehaviorInternal()
Attaches a behavior to this component.
private
attachBehaviorInternal(string|int $name, string|array<string|int, mixed>|Behavior $behavior) : Behavior
Parameters
- $name : string|int
-
the name of the behavior. If this is an integer, it means the behavior is an anonymous one. Otherwise, the behavior is a named one and any existing behavior with the same name will be detached first.
- $behavior : string|array<string|int, mixed>|Behavior
-
the behavior to be attached
Return values
Behavior —the attached behavior.
registerFile()
Registers a JS or CSS file.
private
registerFile(string $type, string $url[, array<string|int, mixed> $options = [] ][, string|null $key = null ]) : mixed
Parameters
- $type : string
-
type (js or css) of the file.
- $url : string
-
the JS file to be registered.
- $options : array<string|int, mixed> = []
-
the HTML attributes for the script tag. The following options are specially handled and are not treated as HTML attributes:
-
depends
: array, specifies the names of the asset bundles that this CSS file depends on. -
appendTimestamp
: bool whether to append a timestamp to the URL.
-
- $key : string|null = null
-
the key that identifies the JS script file. If null, it will use $url as the key. If two JS files are registered with the same key at the same position, the latter will overwrite the former. Note that position option takes precedence, thus files registered with the same key, but different position option will not override each other.
Tags
registerViewContext()
Registers the client viewContext.
private
registerViewContext() : mixed
renderEndPage()
Render of ending page with all attached assets.
private
renderEndPage() : mixed
This method doesn't mark a page is ended in order to allow to call it several times.