다음 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
문제는이 정확한 코드가 내가 가지고 있던 다른 프로젝트에서 잘 작동한다는 것입니다. 경로 설정과 컨트롤러 및 모델을 복사 한 후이 새 프로젝트에서 작동하지 않기로 결정했습니다. 코드의 차이점을 볼 수 없기 때문에 여기서 중요한 단계를 놓친 것 같습니다.
어떤 아이디어?
잘못된 URL을 사용하고 있습니다. 이 URL :
http://myserver.dev/admin/import-items/1
대신 이것이어야한다
http://myserver.dev/admin/items/import-items/1
또는
Route::get('items/import-items/{after?}', array('as' => 'importItems', 'uses' => 'ItemsController@importItems'));
해야한다
Route::get('import-items/{after?}', array('as' => 'importItems', 'uses' => 'ItemsController@importItems'));
... 원하는 URL에 따라 다름
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다