2015-01-17 3 views
-1

laravel php framework을 사용하여 로그인 양식을 쓰고 있습니다. 내가 클릭
Login codelaravel의 앵커 태그를 클릭하면 페이지가 새 페이지로 라우팅되지 않음

<!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'); 
}); 

: 여기에 코드입니다 nchor 링크가 log in page이면 등록 페이지로 리디렉션되지 않습니다. 그러나 localhost:8000localhost:8000/register으로 바꾸면 등록 페이지가 열립니다.
어떻게 해결할 수 있습니까?

답변

1

현재 귀하의 연결 지점은 /register.php이고 /register입니다. 당신이 블레이드를 사용하지 않는 경우

{{ link_to('register', 'Click here to register') }} 

또는 : : 그냥 그 변경 :

<a href="/register">Click here to register</a> 

또는 더 나은 접근 방식을, URL 또는 심지어 전체 링크를 생성하기위한 Laravels 도우미 기능을 사용

<?php echo link_to('register', 'Click here to register'); ?> 

대부분의 URL 도우미 함수는 here으로 표시됩니다.
하나의 중요성이 누락되었습니다. Url::to('your/url')은 라우트의 이름을 지정하거나 특정 컨트롤러 조치를 지정할 필요없이 절대 URL을 생성합니다.

1

을 읽고 아래

<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> 

처럼 블레이드 변경 앵커의 HREF를 사용하는 경우에 URL :() 또는 경로 ('routeName', $의 PARAMS) 함수를 사용할 필요가 login.php의 코드를 살펴보십시오 : 링크는 "register.php"를 가리 키지 만 정의한 경로에 따라 "/ register"여야합니다.

관련 문제