简体   繁体   中英

How to Use Session in Getherbert [Laravel]?

I use Gethebert ( http://getherbert.com/ ) as plugin in wordpress. This one is having structure as Laravel framework.

Also it uses mostly same components as laravel used.

But my query is how to use its session.

In laravel i use,

Session::put('name','value');         //to Set Session Value

and

Session::get('name');                //to Get Session Value

But in Getherbert, I dont know the right way to use session.

Suggest me the right one....

Thank you !

You can always use standard PHP $_SESSION :

http://php.net/manual/en/session.examples.php

For example to put:

$_SESSION['name'] = $value;

And to get:

$value = $_SESSION['name'];

Below you can find , how to use session in Laravel.

Setting a single variable in session :-

syntax :- Session::put('key', 'value');
example :- Session::put('email', $data['email']); //array index
           Session::put('email', $email); // a single variable
           Session::put('email', 'test@test.com'); // a string

Retrieving value from session :-

syntax :- Session::get('key');
example :- Session::get('email');

Checking a variable exist in session :-

// Checking email key exist in session.
if (Session::has('email')) {
  echo Session::get('email');
}

Deleting a variable from session :-

syntax :- Session::forget('key');
example :- Session::forget('email');

Removing all variables from session :-

Session::flush();

Source : http://tutsnare.com/how-to-use-session-in-laravel/

Thank to all...

Finally i got answer for using session in Getherbert[laravel],

here it is,

use Herbert\Framework\Session;

class Admin extends MyCore{

   function index(){
       session()->set('age',24);
       dd(session()->get('age'));
  }
}

OUTPUT :

  24

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM