简体   繁体   English

Slim Framework 3会议

[英]Slim Framework 3 session

Could you please help me, My code is not saving SESSION between requests. 您能帮我吗,我的代码没有在请求之间保存SESSION。

when i Login, it always returns null in session. 当我登录时,它总是在会话中返回null。

Thank you in advance. 先感谢您。

$app->get('/session', function($request, $response, $args) {
    $session = new \SlimSession\Helper;

    $reponse["uid"] = $session->uid;
    $reponse["email"] = $session->email;
    $reponse["name"] = $session->name;
    echo json_encode($reponse);
});

$app->post('/connexion', function ($request, $response, $args) {

            $reponse['status'] = "success";
            $reponse['message'] = 'Vous êtes connecté.';
            $reponse['name'] = "wassim boukadida";
            $reponse['uid'] = "123456";
            $reponse['email'] = "test@test.com";
            $reponse['createdAt'] = "date_exmple";

            //session saving
            $session = new \SlimSession\Helper;
            $session->uid = "123456";
            $session->email = "test@test.com";
            $session->name = "wassim boukadida";
    echo json_encode($reponse);

});

You need to start the session, bryanjhv/slim-session has already middleware for that, which you just need to add: 您需要启动会话, bryanjhv/slim-session已经有相应的中间件,您只需添加:

$app = new \Slim\App;

// add the middleware
$app->add(new \Slim\Middleware\Session());

// add routes

$app->run();

For settings look at the readme file of bryanjhv/slim-session as this helper is currently in development 对于设置,请查看bryanjhv/slim-session自述文件,因为该助手当前正在开发中

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

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