Welcome Guest, Not a member yet? Register   Sign In
Routes: how to get mycontroller/id function same as mycontroller/action/id
#7

[eluser]marcoss[/eluser]
[quote author="dreamynsx" date="1192840619"]Well the real idea for all this is that my index action will show a list of cars, and can accept a category

Lets say I have 20 categories. I wouldn't want to create 20 different methods just to support this.

So back to the function index($cat="") { ... }

www.site.com/cars/index/sports <-- works (shows 'sport' cars)

www.site.com/cars <-- works (just show default list)

www.site.com/cars/sports <-- fails ...[/quote]

Again, you are missing the point here, it is about architecture, you should do something like this

Code:
class MyController extends Controller
{
    function index()
    {
        // load home
    }

    function show($cat=0,$id=0) {
       if($id) // get record by $id in $cat
       else    // get all records in $cat
    }

}

Now you have,

http://site.com/cars/show/sports --&gt; will list all cars on sports category.
http://site.com/cars/show/sports/5 --&gt; will get the car with id 5 in the sports category.


Messages In This Thread
Routes: how to get mycontroller/id function same as mycontroller/action/id - by El Forum - 10-20-2007, 12:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB