简体   繁体   English

如何在Getherbert [Laravel]中使用会话?

[英]How to Use Session in Getherbert [Laravel]?

I use Gethebert ( http://getherbert.com/ ) as plugin in wordpress. 我使用Gethebert( http://getherbert.com/ )作为wordpress中的插件。 This one is having structure as Laravel framework. 这是一个具有Laravel框架的结构。

Also it uses mostly same components as laravel used. 此外,它使用的组件与laravel所使用的组件基本相同。

But my query is how to use its session. 但是我的查询是如何使用其会话。

In laravel i use, 在laravel中,我使用

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. 但是在Getherbert中,我不知道使用会话的正确方法。

Suggest me the right one.... 向我建议合适的一个...。

Thank you ! 谢谢 !

You can always use standard PHP $_SESSION : 您可以随时使用标准PHP $_SESSION

http://php.net/manual/en/session.examples.php http://php.net/manual/zh/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. 在下面您可以找到如何在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/ 资料来源: http : //tutsnare.com/how-to-use-session-in-laravel/

Thank to all... 谢谢大家...

Finally i got answer for using session in Getherbert[laravel], 最后,我得到了在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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