php - Laravel route pass variable to controller -
how pass hard coded variable controller?
my route is:
route::group(array('prefix' => $locale), function() { route::get('/milk', array('as' => 'milk', 'uses' => 'productscontroller@index')); });
i want like:
route::get('/milk', array('as' => 'milk', 'uses' => 'productscontroller@index(1)'));
but doesn't work.
how can done?
sorry if have not explained well.
i wish hardcode (set in stone me) type_id routes so:
route::get('/milk', array('as' => 'milk', 'uses' => 'productscontroller@index(1)')); route::get('/cheese', array('as' => 'cheese', 'uses' => 'productscontroller@index(2)')); ...
my productscontroller reference:
class productscontroller extends basecontroller { public function index($type_id) { $products = new products; $products = $products->where('type_id', $type_id)->get(); homecoming view::make('products.products', array('products' => $products)); } }
you can utilize closure route , phone call controller action:
route::get('/milk', array('as' => 'milk', function(){ homecoming app::make('productscontroller')->index(1); }));
however nicer way be, utilize where
status , type-to-id conversion in controller... loose direct alias thought , have pass in product parameter when generating url.
route::get('{product}', array('as' => 'product', 'uses' => 'productscontroller@index')) ->where('product', '(milk|cheese)');
php laravel laravel-4 laravel-routing
No comments:
Post a Comment