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

[eluser]dreamynsx[/eluser]
Hello, I've read routes documentation already, but it really does not have a lot of examples for what I'm trying to do. Please help.

Code:
// my sample class with index action
class MyController extends Controller
{
    function index($id="")
    {
        // do fun things here
    }

    function add() {
       // do more fun things here
    }

}


How do I get it so that both requests like this work:

www.site.com/mycontroller/index/3<-- this works by default, sets $id value to 3

www.site.com/mycontroller/3 <-- this fails with 404, since '3' is not valid action

www.site.com/mycontroller/add <-- this works as expected

www.site.com/mycontroller <-- this will work and load index action by default


This is simply because I don't want to use url like www.site.com/cars/index/3 as I think having index at the end of every section looks funny. So www.site.com/cars/3 is what I want to work.


Thanks!


Messages In This Thread
Routes: how to get mycontroller/id function same as mycontroller/action/id - by El Forum - 10-19-2007, 10:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB