Laravel等效或替代CodeIgniter

问题描述:

I am trying to figure out how to do the equivalent of the following in Laravel that I would do in CodeIgniter all the time to build views:

$section = $this->load->view('pages/about', $data, TRUE);

This would allow me to echo $section in another view file and then when that view was called the normal way, it would render it. I am not sure how to do something like this in Laravel.

UPDATE

I figured it out. What I was needing was Laravel's HtmlString class to take a string and convert it to html markup to the view file.

我试图找出如何在Laravel中完成以下相同的工作,我会在CodeIgniter中做所有的 构建视图的时间: p>

  $ section = $ this-> load-> view('pages / about',$ data,TRUE); 
  code  >  pre> 
 
 

这将允许我在另一个视图文件中回显 $ section code>,然后当以正常方式调用该视图时,它将呈现它。 我不确定如何在Laravel中做这样的事情。 p>

更新 p>

我弄明白了。 我需要的是Laravel的HtmlString类,它接受一个字符串并将其转换为html标记到视图文件。 p> div>

You would need to use the View Facade, so make sure to include it with an "Use" statement in your Controller, but basically is this:

$html = View::make('pages/about', $data)->render();

The render() method will just render the view in HTML, instead of returning it as a Response object like the view() helper function does.

There are several ways to do so, try this:

return view('admin.profile', $data);

Read through this doc: https://laravel.com/docs/5.5/views