Laravel 5:链接到 php 页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31673049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:04:04  来源:igfitidea点击:

Laravel 5 : link to php page

phplaravellaravel-5

提问by Gammer

I have two pages login.blade.phpand register.blade.php. On my login.blade.phpi have link to register.blade.phplike this :

我有两页login.blade.phpregister.blade.php. 在我的login.blade.php我有这样的链接register.blade.php

<a href="register.php">Register a new membership</a>

When i click on the link to register.php it throws the following error :

当我点击 register.php 的链接时,它会引发以下错误:

NotFoundHttpException in RouteCollection.php line 143:

NotFoundHttpException in RouteCollection.php line 143:

Both login and register are in the same views folder.

login 和 register 都在同一个 views 文件夹中。

My route.php file have :

我的 route.php 文件有:

Route::get('/register', function(){
    return view('register');
});

回答by davsp

Two things need to happen:

有两件事需要发生:

1) Remove the .php in your tag. It should be as such:

1) 删除标签中的 .php。它应该是这样的:

<a href="register">Register a new membership</a>

2) Make sure you are catching the 'register' route properly:

2) 确保您正确捕捉“注册”路线:

Route::get('register', function()
{
    return view('register');
});

回答by Zahoor Ahmed

At first give a name to your route and then use it in then use it in anchar tag

首先为您的路线命名,然后在其中使用它,然后在 anchar 标签中使用它

Route::get('/', function () {
    return view('welcome');
})->name('welcome');
Route::get('/about', 'PagesController@about')->name('about');

Now you can use it in any page to refer them. like in contact page

现在您可以在任何页面中使用它来引用它们。喜欢在联系页面

<html>
..
....
<a href="{{route('welcome')}}">Home</a>
<a href="{{route('about')}}">About</a>