Laravel 4:无法生成URL,因为此类路由不存在

Laravel 4:无法生成URL,因为此类路由不存在

问题描述:

Here is my routes.php:

Route::group(['prefix' => 'mine'], function () {
    Route::get('/first', ['as' => 'mine.first', 'uses' => 'MyApp\Controllers\MyController@first']);
});

Here is my HTML/Twig file:

{{ form_open({'action': 'mine.first'}) }}
{{ form_submit('Start') }}
{{ form_close }}

And here is my controller:

class MyController extends BaseController {
    public function first()
    {
        \View::make('stuff.mine.first'); //in folder app/views/stuff/mine
    }
}

The error is "An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "MyController@first" as such route does not exist.") in "stuff.show" at line 130."

All the answers on this topic that I've seen are to name the route, but I've already done that.

Also, when I go to the URL manually (localhost/mine/first), the screen is blank even though there is HTML in that file.

Any idea what's going on? Thanks.

这是我的routes.php: p>

  Route ::  group(['prefix'=>'mine'],function(){
 Route :: get('/ first',['as'=>'mine.first','uses'=>' 我的HTML / Twig文件: p> 
 
  pre>  {{form_open({'action':'mine.first'}}}} 
 {{form_submit('Start')}} 
 {{form_close}} 
  code>   pre> 
 
 

这是我的控制器: p>

 类MyController扩展BaseController {
公共函数first()
 {
 \ View :: 使( 'stuff.mine.first');  //在文件夹app / views / stuff / mine 
} 
} 
  code>  pre> 
 
 

错误是“在呈现模板期间抛出了异常( “无法生成指定路由的URL”MyController @ first“因为这样的路由不存在。”)在第130行的“stuff.show”中。“ p>

所有答案都在 我所看到的这个话题就是为这条路线命名,但我已经做到了。 p>

此外,当我手动转到URL(localhost / mine / first)时,即使该文件中有HTML,屏幕仍为空白。 p> 知道发生了什么事吗? 谢谢。 p> div>

mine.first is a route name, not an action.

Use:

{{ form_open({'route': 'mine.first'}) }}

As for the view, controller action need to return a Response (the View generates one), so you just need add the proper keyword:

  public function first()
  {
     return \View::make('stuff.mine.first');
  }