我使用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
替换localhost:8000/register
时,会打开注册页面
我该如何解决?
答案 0 :(得分:1)
目前,您的链接指向/register.php
您想要的内容/register
。只需改变一下:
<a href="/register">Click here to register</a>
或者更好的方法,使用Laravels帮助函数生成URL甚至是完整链接:
{{ link_to('register', 'Click here to register') }}
或者如果你没有使用Blade:
<?php echo link_to('register', 'Click here to register'); ?>
列出了大多数URL帮助程序函数here
但是有一个重要的缺失:Url::to('your/url')
只会生成绝对URL而无需为路由命名或定位特定的控制器操作。
答案 1 :(得分:1)
如果您正在使用刀片更改主播&#39; s href,则需要使用URL :: to()或路由(&#39; routeName&#39;,$ 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>
答案 2 :(得分:1)
查看login.php中的代码:您的链接指向&#34; register.php&#34;,但应该是&#34; / register&#34;根据您定义的路线。