Laravel 5 framework learning - transferring data to views (advanced), laravel framework_PHP tutorial

WBOY
Release: 2016-07-13 09:57:42
Original
957 people have browsed it

Laravel 5 framework learning - transmitting data to the view (advanced), laravel framework

We can not only transmit a data to the view, we can also transmit Array

Copy code The code is as follows:
Public function about()
{
          return view('pages.about')->with([
             'first' => 'Zhang',
'last' => 'Jinglin'
]);
}

About {{ $first }} {{ $last }}


A concise way is this:

Copy code The code is as follows:
Public function about()
{
          $data = [];
         $data['first'] = 'Zhang';
         $data['last'] = 'Jinglin';
          return view('pages.about', $data);
}

The result is the same, simpler is this:

Copy code The code is as follows:
Public function about()
{
          $first = 'Zhang';
          $last = 'Jinglin';
          return view('pages.about', compact('first', 'last'));
}

compact turns the parameters into arrays, and extract does the opposite. You can check the php manual to learn about compact, and take a look at extract.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/980217.htmlTechArticleLaravel 5 framework learning to transfer data to the view (advanced), in the laravel framework we can not only transfer data to the view A piece of data, we can also transfer Array. The code is as follows:...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!