Reputation: 2199
I have this route in a laravel 4 app:
Route::controller('about','AboutController');
When I go to http://website/about/imprint
I get the imprint, but when I go to http://website/about/imprint/12345
, (which is not used in the controller) I get the imprint as well. It does not throw an error.
Is this a problem? Should I somehow catch it and show a 404 error, or does it not matter?
I can even go to http://website/about/imprint/7/7/7/7
for example, without getting an error message.
the AboutController
looks so:
<?php
class AboutController extends BaseController
{
public function getIndex()
{
return View::make('about');
}
public function getImprint()
{
return View::make('imprint');
}
public function getDatenschutz()
{
return View::make('datenschutz');
}
}
Upvotes: 1
Views: 365
Reputation: 355
I prefer to use something like this for my routes:
Route::get('/about/imprint', 'AboutController@getImprint')
But that is just my opinion. With this syntax, it automatically gives the NotFoundHTTPException for something like this '/about/imprint/7/7/7/7/7/7/7' so you don't have to check for it.
Now if you want extra stuff, you could have a different route for that such as:
Route::get('/about/imprint/{id}', 'AboutController@getImprint')->where('id', '[0-9]+');
Then getImprint() would look like this:
function getImprint($id){
// can only get here if id is a number (based on where clause)
}
Upvotes: 1
Reputation: 7879
Anything after imprint/
is being passed into your getImprint()
function as arguments. You can see this by changing your getImprint() function to print out the arguments, like so:
public function getImprint() {
return "Imprint <br />Args: " . print_r(func_get_args(), true);
}
Then http://website/about/imprint/12345
would return a page that looks like this:
Imprint
Args: Array ( [0] => 12345 )
and http://website/about/imprint/7/8/9/10
would return a page that looks like this:
Imprint
Args: Array ( [0] => 7 [1] => 8 [2] => 9 [3] => 10 )
Upvotes: 1