Behaviors

Defining Behaviors Handling Component Events Attaching Behaviors Using Behaviors Detaching Behaviors Using TimestampBehavior Other behaviors Comparing Behaviors with Traits Behaviors are instances of yii\base\Behavior, or of a child class. Behaviors, also known as mixins, allow you to enhance the functionality of an existing component class without needing to change the class's inheritance. Attaching a behavior to a component "injects" the behavior's methods and properties into the component,

base\Widget widget()

widget() public static method Creates a widget instance and runs it. The widget rendering result is returned by this method. public static string widget ( $config = [] )$config array Name-value pairs that will be used to initialize the object properties return string The rendering result of the widget. throws Exception

base\Widget setView()

setView() public method Sets the view object to be used by this widget. public void setView ( $view )$view yii\base\View The view object that can be used to render views or view files.

base\Widget setId()

setId() public method Sets the ID of the widget. public void setId ( $value )$value string Id of the widget.

base\Widget run()

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

base\Widget renderFile()

renderFile() public method Renders a view file. public string renderFile ( $file, $params = [] )$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. throws yii\base\InvalidParamException if the view file does not exist.

base\Widget render()

render() public method Renders a view. 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 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 view path of the cu

base\Widget getViewPath()

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

base\Widget getView()

getView() public method Returns the view object that can be used to render views or view files. The render() and 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 yii\web\View getView ( )return yii\web\View The view object that can be used to render views or view files.

base\Widget getId()

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