Laravel 4.2 Session

Source: Internet
Author: User

Laravel's session brief API

Session API is relatively simple, we look at the Chinese document also probably know how to mean. But there are a few that are not very well understood.

    1. Permanent Save of Session (within the non-expiring range)
    2. Session::p ut (' key ', ' value ');
    3. Native session equivalent to PHP
    4. $_session[' key ' = ' value ';
    5. Get operation
    6. $value = Session::get (' key ', ' default ');
    7. Remove operation and Delete, similar to pop concept
    8. $value = Session::p ull (' key ', ' default ');
    9. Detect if a key exists
    10. Session::has (' users ');
    11. Delete key
    12. Session::forget (' key ');
Set the value in session
Public Function Session1 (Request $request) {
1.HTTP request session ();
/* $request->session ()->put (' Key1 ', ' value1 ');
echo $request->session ()->get (' Key1 '); */

2.session ()
/*session ()->put (' Key2 ', ' value2 ');
echo session ()->get (' Key2 '); */

3.session
storing data to session
Session::p ut (' Key3 ', ' value3 ');

Get the data in session
echo session::get (' Key3 ');

Does not exist then gets the default value
echo session::get (' Key4 ', ' Default ');

Storing data as an array
Session::p ut ([' key4 ' = ' value4 ']);

Put the data in the array of the session
/*session::p ush (' user ', ' yxh ');
Session::p ush (' user ', ' IMOOC '); */

Extracting data from an array
/* $res = session::get (' user ', ' default ');
Var_dump ($res); * *

Remove the data and delete it
/* $res = Session::p ull (' user ', ' default ');
Var_dump ($res); * *

Take out the ownership in the session
/* $res = Session::all ();
Var_dump ($res); * *

Determine if a value exists in the session
/*if (Session::has (' Key1 ')) {
$res = Session::all ();
DD ($res);
}else{
Echo ' does not exist ';
}*/

Delete the value specified in the session
Session::forget (' Key1 ');

Clear all session
Session::flush ();

Set temporary data, access only once, second access deletes
Session::flash (' Key-flash ', ' Flash ');
}

Laravel 4.2 Session

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.