我正在使用laravel php framework
编写登录表单。这是代码:
Login code
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
<style>
@import url(//fonts.googleapis.com/css?family=Lato:700);
body {
margin:0;
font-family:'Lato', sans-serif;
text-align:center;
color: #999;
}
.welcome {
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -100px;
}
a, a:visited {
text-decoration:none;
}
h1 {
font-size: 32px;
margin: 16px 0 0 0;
}
</style>
</head>
<body>
<div class="welcome">
<form action="POST">
User Name: <input type="text"><br>
Password: <input type="password"><br>
<input type="submit" value="Submit"><br>
<a href="register.php">Click here to register</a>
</form>
</div>
</body>
</html>
Registration code
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
<style>
@import url(//fonts.googleapis.com/css?family=Lato:700);
body {
margin:0;
font-family:'Lato', sans-serif;
text-align:center;
color: #999;
}
.welcome {
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -100px;
}
a, a:visited {
text-decoration:none;
}
h1 {
font-size: 32px;
margin: 16px 0 0 0;
}
</style>
</head>
<body>
<div class="welcome">
<form action="POST">
First Name: <input type="text"><br>
Last Name: <input type="text"><br>
Password: <input type="password"><br>
Email id: <input type="email"><br>
<input type="submit" value="Submit"><br>
</form>
</div>
</body>
</html>
Routes.php
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function()
{
return View::make('hello');
});
Route::get('/register', function()
{
return View::make('register');
});
当我在log in page
中单击锚链接时,它不会被重定向到注册页面。但是当我用localhost:8000/register
替换localhost:8000
时,注册页面会打开。
我该如何解决它?
目前,您的链接指向/register.php
您想要的是/register
。只需更改它:
<a href="/register">Click here to register</a>
或者更好的方法,使用 Laravels 辅助函数生成 URL 甚至完整链接:
{{ link_to('register', 'Click here to register') }}
或者,如果您没有使用刀片:
<?php echo link_to('register', 'Click here to register'); ?>
此处列出了大多数 URL 帮助程序函数。
但是,这里缺少一个重要内容:Url::to('your/url')
只会生成一个绝对URL,而无需命名路由或定位特定的控制器操作。
如果你使用刀片更改锚点的href,你需要使用URL::to()或route('routeName',$params)函数
,如下所示<div class="welcome">
<form action="POST">
User Name: <input type="text"><br>
Password: <input type="password"><br>
<input type="submit" value="Submit"><br>
<a href="{{ URL::to('register') }}">Click here to register</a>
</form>
</div>
阅读路由文档
查看登录中的代码.php :您的链接指向"注册.php",但根据您定义的路由应该是"/register"。