Ticket Details

HtmlHelper link and and ID param

BUG Ticket (closed)

###What happened:
- A link method call does not return the expected result (the correct path)
The following code
{{{
$this->html->link('Show', array('action' => 'show', 'id' => $model->_id));
}}}
returns the current path:
http://localhost/controller/index or http://localhost/controller/

###What was expected:
- when an id is supplied, the path is not set correctly. when the id is not supplied, the path is ok (the action is correct).

The following code
{{{
$this->html->link('Show', array('action' => 'show'));
}}}
returns the current path:
http://localhost/controller/show/

###Additional Infos
It should be no problem to supply a hardcoded string as a path, but i suppose it should work with an array too?

System is Ubuntu Linux with Cherokee-Setup as described in the tutorial. The id comes from mongo. (It doesnt work with an hard-coded id too).

kind regards,
mike
on 03.10.10 reported by: daschl owned by: nate

Updates

on 03.10.10 by rafalfilipek
Id is an argument in url so You have to put it into ```args``` array:
{{{
<?=$this->html->link($post->title, array('action' => 'show', 'args'=> array('id' => $post->_id)));?>
}}}
on 03.10.10 by daschl
ah ok thank you for that input. i had a look at the routes file and thought that "id" was treated specially like "action" and "controller" because its use is so common.

@devs: is the use of id as an argument intended or should the ticket be not a bug but an enhancement?

regards,
mike
on 03.11.10 by daschl
lithium_mongo uses the same syntax, so maybe its actually a bug?

http://rad-dev.org/lithium_mongo/source/views/elements/collections.html.php

{{{
$this->html->link($collection, array('controller' => 'collections', 'action' => 'view', 'id' => $collection));
}}}
on 03.11.10 by gwoo
It has to do with this route where the regex is not reverse properly.
{{{
Router::connect('/{:controller}/{:action}/{:id:[0-9]+}');
}}}

Using the route below should work.
{{{
Router::connect('/{:controller}/{:action}/{:id}');
}}}
on 03.12.10 by daschl
When i change the route as suggested, the show, edit and delete routes work perfectly, but a simple add without the id doesnt work (i get redirected to my default route which is an index method)

Defined Routes:
{{{
Router::connect('/{:controller}/{:action}/{:id}.{:type}', array('id' => null));
Router::connect('/{:controller}/{:action}/{:id}');
Router::connect('/{:controller}/{:action}/{:args}');
}}}

My Links:
{{{
<?= $this->html->link('Add New', array('controller' => 'defis', 'action' => 'add')); ?>

<?= $this->html->link($this->html->image('admin/show.png', array('alt' => 'Show', 'title' => 'Show')), array('action' => 'show', 'id' => $defi->_id), array('escape' => false)); ?>
<?= $this->html->link($this->html->image('admin/edit.png', array('alt' => 'Edit', 'title' => 'Edit')), array('action' => 'edit', 'id' => $defi->_id), array('escape' => false)); ?>
<?= $this->html->link($this->html->image('admin/delete.png', array('alt' => 'Delete', 'title' => 'Delete')), array('action' => 'delete', 'id' => $defi->_id), array('escape' => false)); ?>                   
}}}

{{{
Current Page: domain.tld/defis/index
Add: domain.tld/defis/add
Edit: domain.tld/defis/edit/<HASH>
Show: domain.tld/defis/show/<HASH>
Delete: domain.tld/defis/delete/<HASH>
}}}

All links point to the correct route, but when i click the add link i come back to my index page (from where i execute these links). The other three links work as requested.
on 03.28.10 by nate
  • status was changed to on hold
Hi Daschl, thanks for the report. If you are being **redirected** to the index page, it sounds like something that's happening within your application code.

If possible, please create a test case for the `Router` class that demonstrates the issue.
(reopened) on 10.04.10 by nate
  • status was changed to pending
(works-for-me) on 10.04.10 by nate
  • owner was changed to nate
  • status was changed to closed
  • resolution was changed to works-for-me