PHP Class yii\base\Widget

For more details and usage information on Widget, see the guide article on widgets.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends Component, implements yii\base\ViewContextInterface
Mostrar archivo Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$autoIdPrefix the prefix to the automatically generated widget IDs.
$counter a counter used to generate [[id]] for widgets.
$stack the widgets that are currently being rendered (not ended). This property is maintained by Widget::begin and Widget::end methods.

Public Methods

Method Description
begin ( array $config = [] ) : static Begins a widget.
end ( ) : static Ends a widget.
getId ( boolean $autoGenerate = true ) : string Returns the ID of the widget.
getView ( ) : View Returns the view object that can be used to render views or view files.
getViewPath ( ) : string Returns the directory containing the view files for this widget.
render ( string $view, array $params = [] ) : string Renders a view.
renderFile ( string $file, array $params = [] ) : string Renders a view file.
run ( ) : string Executes the widget.
setId ( string $value ) Sets the ID of the widget.
setView ( View $view ) Sets the view object to be used by this widget.
widget ( array $config = [] ) : string Creates a widget instance and runs it.

Method Details

begin() public static method

This method creates an instance of the calling class. It will apply the configuration to the created instance. A matching Widget::end call should be called later. As some widgets may use output buffering, the Widget::end call should be made in the same view to avoid breaking the nesting of output buffers.
See also: end()
public static begin ( array $config = [] ) : static
$config array name-value pairs that will be used to initialize the object properties
return static the newly created widget instance

end() public static method

Note that the rendering result of the widget is directly echoed out.
See also: begin()
public static end ( ) : static
return static the widget instance that is ended.

getId() public method

Returns the ID of the widget.
public getId ( boolean $autoGenerate = true ) : string
$autoGenerate boolean whether to generate an ID if it is not set previously
return string ID of the widget.

getView() public method

The Widget::render and Widget::renderFile methods will use this view object to implement the actual view rendering. If not set, it will default to the "view" application component.
public getView ( ) : View
return yii\web\View the view object that can be used to render views or view files.

getViewPath() public method

The default implementation returns the 'views' subdirectory under the directory containing the widget class file.
public getViewPath ( ) : string
return string the directory containing the view files for this widget.

render() public method

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 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 currently active module. - relative path (e.g. "index"): the actual view file will be looked for under [[viewPath]]. If the view name does not contain a file extension, it will use the default one .php.
public render ( string $view, array $params = [] ) : string
$view string the view name.
$params array the parameters (name-value pairs) that should be made available in the view.
return string the rendering result.

renderFile() public method

Renders a view file.
public renderFile ( string $file, array $params = [] ) : string
$file string the view file to be rendered. This can be either a file path or a path alias.
$params array the parameters (name-value pairs) that should be made available in the view.
return string the rendering result.

run() public method

Executes the widget.
public run ( ) : string
return string the result of widget execution to be outputted.

setId() public method

Sets the ID of the widget.
public setId ( string $value )
$value string id of the widget.

setView() public method

Sets the view object to be used by this widget.
public setView ( View $view )
$view View the view object that can be used to render views or view files.

widget() public static method

The widget rendering result is returned by this method.
public static widget ( array $config = [] ) : string
$config array name-value pairs that will be used to initialize the object properties
return string the rendering result of the widget.

Property Details

$autoIdPrefix public_oe static_oe property

the prefix to the automatically generated widget IDs.
See also: getId()
public static $autoIdPrefix

$counter public_oe static_oe property

a counter used to generate [[id]] for widgets.
public static $counter

$stack public_oe static_oe property

the widgets that are currently being rendered (not ended). This property is maintained by Widget::begin and Widget::end methods.
public static $stack