Development

#2315 (Using link_to() with an anchor results in variables not being passed)

You must first sign up to be able to contribute.

Ticket #2315 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

Using link_to() with an anchor results in variables not being passed

Reported by: Brian.Kendig Assigned to: fabien
Priority: minor Milestone: 1.1.0 RC2
Component: helpers Version: 1.1.0 DEV
Keywords: Cc:
Qualification: Accepted

Description

When I link_to a path containing an anchor, and I try to pass arguments to the destination, the destination action doesn't see any of the arguments I'm trying to give it. Remove the anchor from the link, and it works fine.

Here's an example. My action contains only the line:

$this->baz = $this->getRequestParameter('baz');

And my template contains:

<?php echo link_to('foo', 'common/sandbox#someanchor', array('query_string' => 'baz=3')); ?>

baz is <?php echo $baz; ?>

When I click the link, it should send a value of 3 for $baz, but it doesn't.

But if I remove '#someanchor' from link_to, then this works fine.

The right solution to this might be to add an 'anchor' option to the options array that link_to() accepts.

Change History

05/07/08 09:28:41 changed by FabianLange

  • qualification changed from Unreviewed to Design decision.

proposed solution: 1) make the helper strip the anchor from the route if present and readd it after adding the query string. (problem: can it be that the # might not be considered as anchor? usually it should be but I dont know:-)) 2) add the proposed anchor option to the optionsarray.

Ideally we would implement 1&2 for a more robust solution, but I consider 1) slightly risky due to manipulation the string, which might cause side effects in rare cases.

option 3)

<?php echo link_to('foo', 'common/sandbox', array('query_string' => 'baz=3#someanchor')); ?>

not nice but perhaps a suitable workaround.

05/27/08 22:54:15 changed by FabianLange

  • status changed from new to closed.
  • resolution set to fixed.

(In [9325]) 1.1: added anchor option to link_to helper to work in conjunction with query_string option (including doc and test/bootstrap/functional.php). fixes #2315

05/27/08 22:55:41 changed by FabianLange

  • version changed from 1.0.2 to 1.1.0 DEV.
  • qualification changed from Design decision to Accepted.
  • milestone set to 1.1.0 RC2.

i decided to add the anchor option in sf 1.1 only, as I dont want risk introducing new bugs. the workaround in 3) described above should do the trick for the people needing this. if somebody disagrees feel free to reopen.

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.