Laravel5 framework learning-transfer data to views (Advanced article) _ php instance

Source: Internet
Author: User
In the previous article, we introduced how to transmit data to a view in the Laravel5 framework. Today, we will study how to transmit an array to the view in great detail. We recommend that you use it for reference. We can not only transmit a data record to a view, but also an Array

The Code is as follows:


Public function about ()
{
Return view ('pages. about')-> ([
'First' => 'zhang ',
'Last' => 'jinglin'
]);
}
About {$ first }{{$ last }}

A simple method is as follows:

The Code is as follows:


Public function about ()
{
$ Data = [];
$ Data ['first'] = 'zhang ';
$ Data ['last'] = 'jinglin ';
Return view ('pages. about', $ data );
}

The results are the same, which is simpler:

The Code is as follows:


Public function about ()
{
$ First = 'zhang ';
$ Last = 'jinglin ';
Return view ('pages. about', compact ('first ', 'last '));
}

Compact converts parameters into arrays, and extract is the opposite. You can refer to the php manual to learn about compact and learn about extract by the way.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.