PHP Class luya\web\Controller

Author: nadar
Inheritance: extends yii\web\Controller
Show file Open project: luyadev/luya

Public Methods

Method Description
getModuleLayoutViewPath ( ) : string Returns the path for layout files when using {{\luya\web\Controller::renderLayout}} method. Those module layouts are located in @app/views folder.
getViewPath ( ) : string Override the default Yii controller getViewPath method. To define the template folders in where the templates are located. Why? Basically some modules needs to put theyr templates inside of the client repository.
registerAsset ( string $className ) Helper method for registring an asset into the view.
render ( string $view, array $params = [] ) : string If we are acting in the module context and the layout is empty we only should renderPartial the content.
renderLayout ( string $view, array $params = [] ) : string Luya implementation of layouts for controllers. The method will return a view file wrapped by a custom module layout.

Method Details

getModuleLayoutViewPath() public method

Returns the path for layout files when using {{\luya\web\Controller::renderLayout}} method. Those module layouts are located in @app/views folder.
public getModuleLayoutViewPath ( ) : string
return string The path to the layout for the current Module.

getViewPath() public method

Override the default Yii controller getViewPath method. To define the template folders in where the templates are located. Why? Basically some modules needs to put theyr templates inside of the client repository.
public getViewPath ( ) : string
return string

registerAsset() public method

Helper method for registring an asset into the view.
public registerAsset ( string $className )
$className string The asset class to register, example `app\asset\MyTestAsset`.

render() public method

If we are acting in the module context and the layout is empty we only should renderPartial the content.
public render ( string $view, array $params = [] ) : string
$view string The name of the view file (e.g. index)
$params array The params to assign into the value for key is the variable and value the content.
return string

renderLayout() public method

For example you have a e-store module with a header which returns the basket you can use the module layout in all the actions to retrieve the same header. Example e-store controller class:. php class EstoreController extends \luya\base\Controller { public function actionIndex() { return $this->renderLayout('index', ['content' => 'This is my index content in variabel $content.']); } public function actionBasket() { return $this->renderLayout('basket', ['otherVariable' => 'This is a variable for the basket view file in variable $otherVariable.']); } } The example layout file which is located in @app/views/module/layout could look something like this: php
  • E-Store Frontpage
  • Basket
public renderLayout ( string $view, array $params = [] ) : string
$view string The name of the view file
$params array The params to assign into the view file.
return string Rendered template wrapped by the module layout file.