我想知道为什么它Session
似乎并没有保持它的价值,但它实际上打印了它的价值?我打印出 the 的值,Session
但是当我在不同的选项卡上访问同一页面时,它无法识别它具有值。此外,当页面刷新Session
时变为空......?还有一件事我不确定我在Log Out
按钮中所做的是否正确
这就是我的LogInController.php
<?php
class LogInController extends BaseController {
public function actionLogIn() {
$username = Input::get('username');
$password = Input::get('password');
if(($username == 'batman' and $password == '12345') or ($username == 'robin' and $password == '54321')){
Session::put('username', $username);
return Redirect::route('welcome')
->with('username', $username)
->with('title', 'Welcome!');
}else {
Session::flush();
return Redirect::to('login')
->with('asterisk', 'Invalid username or password')
->with('title', 'Login');
}
}
public function actionLogOut() {
Session::flush();
return View::make('login.formlogin')
->with('title', 'Login');
}
}
这里是routes.php
Route::get('/', function()
{ return View::make('hello'); });
Route::get('login', array('as' => 'login', function ()
{ return View::make('login.formlogin')
->with('title', 'Login');
}));
Route::post('login', array('uses'=>'LogInController@actionLogIn'));
Route::get('error', array('uses'=>'LogInController@actionLogOut'));
Route::get('welcome', array('as' => 'welcome', function ()
{ return View::make('login.uservalid'); }));
formlogin.blade.php
@extends('login.login')
@section('content')
<h3>Login</h3>
{{ Form::open(array('method'=>'post')) }}
<div id="asterisk">{{ Session::get('asterisk') }}</div>
{{ Form::label('username', 'Username:') }}
{{ Form::text('username') }}<br/>
{{ Form::label('password', 'Password:') }}
{{ Form::password('password') }}<br/>
{{ Form::submit('Log In') }}
{{ Form::close() }}
@endsection
uservalid.php
@extends('login.layouts')
@section('content')
{{ Form::open(array('method'=>'get')) }}
welcome
{{ Session::get('username') }}
<br/>
{{ Form::submit('Log Out') }}
{{ Form::close(0) }}
@endsection
layouts.blade.php
为了uservalid.blade.php
<html>
<header>
<title></title>
</header>
<body>
@if(Session::has('username'))
@yield('content')
@else
nothing to do here
@endif
</body>
</html>
谢谢,