![]() |
| Id as root argument |
|
qistoph_
|
Hi all,
For a few days I've been using PHP on Trax just to investigate it's possibilities and acquire some skills in using it. I was wondering if it would be possible to pass the id argument as first 'parameter' in the url. Say I'm running my PHP on Trax application on http://trax.localhost/trax That would make my 'main' controller available at http://trax.localhost/trax/main When I want to give an id as parameter I'd use http://trax.localhost/trax/main/index/1 Now, what I want is to be able to have a url like this: http://trax.localhost/trax/1 So I won't have to enter the controller, nor the action. Is it possible to accomplish this with PHP on Trax? Kind Regards, qistoph |
||||||||||||
|
|
|||||||||||||
|
johnpipi
|
Yes you can do this easily:
in the config/routes.php file:
|
||||||||||||||
|
|
|||||||||||||||
|
johnpipi
|
I did a test and in my routes.php I have these
This worked for me id was set. but it sets the id in the request so $_REQUEST['id'] is how you access it in the controller. The only problem if you had a route like that with only :id it basically overrides everything else and thinks everything is this route. So what you should do is make up a name that no other controller has /:id and use that such as: $router->connect("pictures/:id", array(":controller" => "pictures", ":action" => "show") ); If you went to the url http://www.phpontrax.com/pictures/24 This would load the pictures controller, the show action, and $_REQUEST['id'] would be 24 Hope this helps. |
||||||||||||||
|
|
|||||||||||||||
|
qistoph_
|
Thanks johnpipi.
With a little more debugging I discovered the problem was in my 'url_prefix'. In config/environment.php an example is given in this format: Trax::$url_prefix = "~username"; When I added a trailing slash to the Trax::$url_prefix the routes worked fine. Thanks for your assistence. |
||||||||||||
|
|
|||||||||||||
| Id as root argument |
|
||
|
Content © PHPonTrax.com; Powered by phpBB


