I have three layouts in my layouts folder in main views folder. I added a module called subDomain. In my subDomain module I have a Controller called HomeController. In HomeController there is an action called getDomain()
.
In the getDomain()
action I want to change the main layout to getDomainLayout
. But there is an error when I use a code:
$this->layout = "getDomainLayout";
Yii2 throws:
Invalid Parameter – yii\base\InvalidParamException
The view file does not exist: \myyii2\modules\subDomain\views\layouts\bersih.php
You can add $this->layout = 'main'; in the module init method. The main. php should be located inside the modules view folder under layouts.
Modules are self-contained software units that consist of models, views, controllers, and other supporting components. End users can access the controllers of a module when it is installed in application. For these reasons, modules are often viewed as mini-applications.
You can set the variable in the controller.
class DefaultController extends Controller
{
public $layout = 'main.php';
}
Or by passing the complete path
public $layout = '@frontend/modules/idModule/views/layouts/main.php';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With