I have a link in symfony2.0 generated with twig’s path function like:
<a id="aBtn" href="{{ path("SomeController_someControllerAction",{'section_id':
section_id, 'period_id': period.getId }) }}>A link</a>
And i also have some javascript that updates the “section_id” part of the generated URL every time a user changes a section on the page:
function updateSectionId(id){
var aBtn = $("#aBtn");
var href = aBtn.attr('href');
var splitted = href.split("/");
splitted[splitted.length-2] = id; //My routing puts the period_id at that position
//(Yes i know its pretty hardcoded...)
aBtn.attr('href',splitted.join("/"));
}
I have verified and the link is updated with the corresponding section_id.
However, debugging the action that recieves this request i find out that it always recieves section_id = 1.
public function newQuestionDialogAction($period_id, $section_id){
//$period_id = 1 ALWAYS, regardless of href value on the link.
I am really clueless… am i missing something on twig’s route generation?
EDIT: Here is route configuration
SomeController_someControllerAction:
pattern: /{period_id}/section/{section_id}/someControllerAction
defaults: { _controller: "SomeBundle:SomeController:someControllerAction" }
requirements:
_method: GET
EDIT2:
I have a hunch that the origin of this problem is the jquery-bootstrap plugin “Modal 2” used to execute ajax requests to the server. I’ll let you know if i find the problem. thanks!
So the problem was indeed with my javascript, and the solution is embarrassingly simple. I am posting here in case someone stumbles upon the same problem with the jquery bootstrap library.
Once you call
All the classes “open-dialog” on every element is removed, thus no matter how many times you call $(document).controls() it wont update the onClick event with the correct href. The workaround is to add “open-dialog” class before calling $(document).controls() again.
So, in my case, the solution was to update my updateSectionId method