【发布时间】:2014-05-28 13:18:05
【问题描述】:
尝试运行以下 Laravel 4.1 路由:http://myserver.dev/admin/import-items/1
当我这样做时,我收到以下错误:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Controller method not found.
这是我的路线:
Route::group(array('prefix' => 'admin', 'before' => 'auth'), function()
{
Route::get('items/import-items/{after?}', array('as' => 'importItems', 'uses' => 'ItemsController@importItems'));
Route::get('items/{id}/show', 'ItemsController@show');
Route::resource('items', 'ItemsController');
});
我可以看一下 Items 控制器,方法importItems 肯定在那里:
class ItemsController extends \BaseController {
/**
* Item Model
* @var Item
*/
protected $item;
/**
* Inject the models.
* @param Item $item
*/
public function __construct(Item $item)
{
parent::__construct();
$this->item = $item;
}
/**
* Display a listing of items
*
* @return Response
*/
public function index($items = [])
{
$title = Lang::get('admin/items/title.manage_items');
if (empty($items))
$items = $this->item;
return View::make('admin/items/index', compact('items', 'title'));
}
/**
* Imports Items after specified date.
* @return array
**/
public function importItems($after = 7)
{
$results = Item::importItems($after);
return $results;
}
}
当我运行php artisan routes 时,路线在列表中清楚地显示为可用:
GET|HEAD admin/items/import-items/{after?} | importItems | ItemsController@importItems
问题是,这个确切的代码在我拥有的另一个项目中工作得很好。在我复制了路由设置、控制器和模型之后,它决定不在这个新项目中工作。我觉得我在这里错过了一些关键步骤,因为我看不出代码中有任何差异。
有什么想法吗?
【问题讨论】:
-
请发帖
ItemsController -
你跑
composer dump-autoload了吗? -
是的,运行了
composer dump-autoload,但没有修复。已将ItemsController添加到帖子中。 -
试试
\ItemsController@show -
@AmitGarg 结果相同。