在Laravel 4的安装,使用Jeffrey Way's Laravel 4 Generators,我成立“鸣叫”资源,使用所述脚手架命令从他的例子:Laravel 4 - 变化的资源根路由路径
php artisan generate:scaffold tweet --fields="author:string, body:text"
此产生的模型,视图,控制器,推送类型的迁移和路由信息。迁移数据库后,访问http://localhost:8000/tweets
工作正常,并显示预期的内容。
的routes.php
文件在这一点上的内容是:
Route::resource('tweets', 'TweetsController');
现在我想移动的URL tweets
一个级别为admin/tweets
,因此上述网址应该变成:http://localhost:8000/admin/tweets
。请注意,我并不是将“管理员”视为资源,而是只是为了虚构的组织目的而添加它。
的routes.php文件文件更改为:
Route::resource('admin/tweets', 'TweetsController');
不工作,并显示以下错误:
Unable to generate a URL for the named route "tweets.create" as such route does not exist.
同样使用以下时:
Route::group(array('prefix' => 'admin'), function() {
Route::resource('tweets', 'TweetsController');
});
由于建议在this stackoverflow question。
使用php artisan routes
显示指定的路线现在也有admin
作为其前缀,将tweets.create
转换为admin.tweets.create
。
为什么错误说它找不到tweets.create
?不应该自动解决(通过航线表判断),使用admin.tweets.create
?
如何更改我的路由,以便不再发生此错误?
我刚刚测试过新的资源控制器,它对我来说工作正常。问题不在于路由,它与视图文件检查您的视图文件有链接路由,如'link_to_route('tweets.create','添加新的推文'),这是因为当你添加'admin'作为前缀'tweets.create'不存在,所以将它改为'admin.tweets.create',在你的控制器中,用于 –
感谢您的快速回复!我其实自己也注意到了这一点。在发布问题之前应该看起来更长一些:P – Johannes