Laravel 4 - Setting up routes -
i'm working on site have inherited , having little trouble routing controller.
when visit url www.domain.com/banners/statistics, won't return anything.
i noted when try , link page via banner statistics gives me error on home page.
routes.php
route::resource('banners', 'bannercontroller'); route::get('banners/{banners}/activate', 'bannercontroller@activate'); route::get('banners/{banners}/deactivate', 'bannercontroller@deactivate'); route::get('banners/{banners}/delete', 'bannercontroller@delete'); route::get('banners/{banners}/preview', 'bannercontroller@preview'); route::any('banners/{banners}/cropresize', 'bannercontroller@cropresize'); route::get('banners/statistics', 'bannercontroller@statistics');
bannercontroller.php
public function create() { $data['title'] = 'create banner'; $data['disciplines'] = discipline::lists('name', 'id'); return view::make('admin.banners.create', $data); } public function statistics() { return view::make('admin.banners.statistics'); }
the resource controller provides multiple routes.
including :
get /resource/{resource}
redirecting show action of controller.
list of created routes : http://laravel.com/docs/controllers#resource-controllers
so when call
banners/statistics
laravel think want call show action "statistics" parameter.
to avoid this, can put custom routes above resource controller route.
route::get('banners/{banners}/activate', 'bannercontroller@activate'); route::get('banners/{banners}/deactivate', 'bannercontroller@deactivate'); route::get('banners/{banners}/delete', 'bannercontroller@delete'); route::get('banners/{banners}/preview', 'bannercontroller@preview'); route::any('banners/{banners}/cropresize', 'bannercontroller@cropresize'); route::get('banners/statistics', 'bannercontroller@statistics'); route::resource('banners', 'bannercontroller');
this way laravel call custom route before routes created resource controller.
you can use only
, except
if don't need of resource controller routes.
route::resource('banners', 'bannercontroller', array('except' => array('show')));
Comments
Post a Comment