我是Laravel的新手并且遇到了困难。我正在尝试让表单工作,但是现在我想要的是在按下提交按钮时重定向到页面。问题是重新加载相同的登录页面并且不会发生重定向。请帮忙。
路线档案:
Route::get('/', array('uses' => 'LoginController@showLogin'));
Route::post('/', array('uses' => 'LoginController@doLogin'));
Route::get('hr', function() {
return View::make('hr', array('page_title' => 'HR Area'));
});
登录控制器:
class LoginController extends BaseController {
public function showLogin()
{
return View::make('login', array('page_title' => 'Log in to MANGER'));
}
public function doLogin()
{
echo "Success!";
}
}
这是登录表单:
<!-- The login view -->
<html>
<head>
<title><?php echo $page_title; ?></title>
{{ HTML::style('css/style.css'); }}
<style type="text/css">
#heading {
font-size: 1.5em;
text-align:center;
font-weight: bold;
padding-top: 50px;
color: #323875;
}
#login-form {
margin-left: 350px;
margin-top: 50px;
margin-bottom: 50px;
}
#login-form td {
padding-right: 5px;
padding-bottom: 5px;
}
#other-links {
color: blue;
text-align: center;
}
</style>
</head>
<body>
<div id="wrapper">
<div class="header">
{{ HTML::image('images/bb_logo.png'); }}
</div>
<div id="heading">MANGER Login</div>
<div id="login-form">
<?php
//build the form
echo Form::open(array('url' => '/'));
echo '<table>';
echo '<tr>';
//enter boring brands email id
echo '<td>';
echo Form::label('email', 'Email ID');
echo '</td>';
echo '<td>';
echo Form::text('email', '');
echo '</td>';
echo '</tr>';
echo '<tr>';
//enter password
echo '<td>';
echo Form::label('password', 'Password');
echo '</td>';
echo '<td>';
echo Form::password('password');
echo '</td>';
echo '</tr>';
echo '</table>';
echo '<br/><br/>';
//the submit button
echo Form::submit('Log in');
echo Form::close();
?>
</div>
<div id="other-links">
Forgot password | Register
</div>
<div class="footer">
MANGER © <?php echo date('Y'); ?>
</div>
</div>
</body>
</html>
routes.php:
Route::get('/', array('uses' => 'LoginController@showLogin'));
Route::post('manger/public/hr', array('uses' => 'LoginController@doLogin'));
Route::get('hr', function() {
return View::make('hr', array('page_title' => 'HR Area'));
});
Route::get('employee', function() {
return View::make('employee', array('page_title' => 'Employee Area'));
});
filters.php
<?php
/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function($request)
{
//
});
App::after(function($request, $response)
{
//
});
/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/
Route::filter('auth', function()
{
if (Auth::guest())
{
if (Request::ajax())
{
return Response::make('Unauthorized', 401);
}
else
{
return Redirect::guest('login');
}
}
});
Route::filter('auth.basic', function()
{
return Auth::basic();
});
/*
|--------------------------------------------------------------------------
| Guest Filter
|--------------------------------------------------------------------------
|
| The "guest" filter is the counterpart of the authentication filters as
| it simply checks that the current user is not logged in. A redirect
| response will be issued if they are, which you may freely change.
|
*/
/*Route::filter('guest', function()
{
if (Auth::check()) return Redirect::to('/');
});*/
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function()
{
if (Session::token() != Input::get('_token'))
{
throw new Illuminate\Session\TokenMismatchException;
}
});
请告诉我我做错了什么。 :(
答案 0 :(得分:0)
使用:
echo Form::open(array('url' => '/', 'method' => 'post'))
同时:
public function doLogin()
{
return Redirect::to('your/page');
}