【问题标题】:getting null value from session()从 session() 获取空值
【发布时间】:2017-05-07 16:10:53
【问题描述】:

用户控制器.php

public function contactList(Request $request)
{
    //after removing this if function. it is working 
    if ($request->session()->has('id')) {
        $request->session()->flash('id', 0);
    } 

    try {
        ....//Doing Something.
    } catch(\PDOException $e){
        ...//Doing Something. 
    }
}

public function contactDetail(Request $request,$user_id)
{
    try {
        DB::connection()->getPdo();     
        try {
            $id = User::findOrFail($user_id);
            $request->session()->put('id', $user_id);
            ... //Doing Something.               
        } catch(\Exception $ex) {       
            ... //Doing Something.          
        }
    } catch(\PDOException $e) {
        ... //Doing Something.
    }
}

public function sendMessage(Request $request)
{
    // dd($request->session()->get('id'));
    // dd($request->session()->has('id'));
    if (!$request->session()->has('id')) {
        return redirect()->to('/');     
    }

    $rand = $this->generateRandomString(6); 

    return View::make('sendmessage')->with('random',$rand);
}

函数按上述顺序调用,但在调用sendMessage 函数时。 session(id) 的值显示 null。但调用 session(id) 的 contactDetail 函数值为 1 。为什么 session(id) 发回null 值? . . .我现在卡住了。 函数按上述顺序调用,但在调用 sendMessage 函数时。 session(id) 的值显示为 null。但调用 session(id) 的 contactDetail 函数值为 1 。为什么 session(id) 发回null 值? . . .我现在卡住了。

【问题讨论】:

  • 这些路线在哪里?也许在 routes/api.php 中?
  • 是的。在 routes.php 中

标签: php laravel session flash-message


【解决方案1】:

!session::get('id') 它没有返回错误值。所以将if & else 代码一起替换。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多