Home  >  Article  >  Backend Development  >  Usage issues of $layout in Laravel 5.3 controller

Usage issues of $layout in Laravel 5.3 controller

WBOY
WBOYOriginal
2016-12-01 00:56:451320browse

In L4, you can define the $layout template in the controller and then use it in the request

<code>$this->layout->content = View::make(sth view)</code>

It doesn’t work in L5.3 today, do you have any solutions

Reply content:

In L4, you can define the $layout template in the controller and then use it in the request

<code>$this->layout->content = View::make(sth view)</code>

It doesn’t work in L5.3 today, do you have any solutions

I’m really sorry, I’ve never used L4

Controller in Laravel 5 is a blank class without any variables in it, including layout

Personally, it is recommended to re-read the manual to see how to use the view: https://laravel-china.org/doc... (Chinese)

Many upgrades and changes have been made in 5 and require re-learning.

If you are using

Laravel 5, try using it in the following way, which is to turn fields into methods

<code>// 在 controller 中设置原本4中设置的 $layout 视图值
public $layout_path = 'view_path';
// 提供一个方法获取 layout 视图
public function layout()
{
    return view($this->layout_path);
}
// 使用( 将原本的$this->layout 改成 $this->layout() )
$this->layout()->content = View::make(sth view);</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn