0

I have a problem in 4 laravel already a few days ago and still can not understand. When I run the route directly so -> Route :: get ('/', 'HomeController@getIndex'); access it normally, but when I do it via redirect me back that the file was not found. Below is my code.

my route:

Route::get('/', function()
{
    return Redirect::to('HomeController');
});

my controller:

class HomeController extends BaseController {
    public function getIndex()
    {
        return View::make('home.hello');
    }
}

my view:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>testing</title>
</head>
<body>
    testing
</body>
</html>

error:

The requested URL /HomeController was not found on this server.
4

1 回答 1

0

Redirect::to('HomeController');重定向到 URL,而不是控制器。

用于Redirect::action('HomeController@index');重定向到特定的控制器操作。

但无论如何,你的路线没有意义。/重定向到的路由HomeController没有什么意义,尤其是当(似乎)你没有通往HomeController.

更好的方法是将/路由绑定到您的HomeController

Route::get('/', 'HomeController@getIndex');

文件:

于 2013-06-27T19:41:56.037 回答