Laravel - 路由到“视图”内的文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26582400/
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 10:20:11  来源:igfitidea点击:

Laravel - routing to a folder inside "views"

phplaravellaravel-4routing

提问by Ethan McKee

I'm still new to laravel and learning my way through. Normally, for example, if I want to access the file "login.blade.php" (located in "views" folder), the route would normally be:

我对 laravel 还是个新手,正在学习我的方法。通常,例如,如果我想访问文件“login.blade.php”(位于“views”文件夹中),路径通常是:

Route::get('/login', array('as' => 'login', 'uses' => 'AuthController@getLogin'));

So the above works just fine. But what if I want to have folders inside the "views" folder? For example, I want to route the file "login.php".

所以上面的工作就好了。但是如果我想在“views”文件夹中有文件夹怎么办?例如,我想路由文件“login.php”。

- views 
 -- account 
  --- login.blade.php

I tried using:

我尝试使用:

Route::get('/account/login', array('as' => 'login', 'uses' => 'AuthController@getLogin'));

But I get an error saying "Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException"

但是我收到一条错误消息“Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException”

What am I doing wrong?

我究竟做错了什么?

Thank you.

谢谢你。

采纳答案by brainless

Your understanding on routes and views is not correct.

您对路线和景观的理解是不正确的。

The first parameter of Route::getis the route URI which will be used in your url as domainname.com/routeURIand second parameter can be an array()or closure functionor a string like 'fooController@barAction'. And Route::get()has nothing to do with rendering views. Routes and Views are not that closely coupled as you think.

的第一个参数Route::get是将在您的 url 中使用的路由 URI,domainname.com/routeURI第二个参数可以是一个array()closure function或类似的字符串'fooController@barAction'。并Route::get()有无关渲染视图。Routes 和 Views 并没有你想象的那么紧密耦合。

This can be done by closures like below

这可以通过像下面这样的闭包来完成

Route::get('login', array('as' => 'login', function()
{
    return View::make('account.login');
}));

Or with controller action

或者使用控制器操作

Route file:

路由文件:

Route::get('login', array('as' => 'login', 'uses' => 'AuthController@getLogin'));

AuthController file:

AuthController 文件:

public function getLogin()
{
    return View::make('account.login');
}

You can find more at http://laravel.com/docs/4.2/routingor If you prefer video tutorials, go to http://laracasts.com

您可以在http://laravel.com/docs/4.2/routing 上找到更多信息,或者如果您更喜欢视频教程,请访问http://laracasts.com

回答by Anand Patel

you need to write following code in AuthController.php Controller

您需要在 AuthController.php Controller 中编写以下代码

public function getLogin()
{
      return View::make("account.login");
}