November 13, 2012, 10:32pm
The goal: rewrite urls like mycontroller/something?var1=first&var2=second to /seoname/first-second
The problem: Url rewrite works well when I’m using link, but doesn’t when I’m using form.
So it [color="
#00FF00"]works[/color] great if I use:
CHtml::link('something', array('var1'=>'first', 'var2'=>'second'));
But when I use the following, it [color="
#FF0000"]doesn’t[/color] rewrite the url:
<input type="hidden" name="var1" value="first">
I have the following rule in config/main.php:
Any ideas how to make it work with form, also?
The building of the URL is done by the HTML Form and than, I think that PHP have not control on it.
A possibly solution should be to use jQuery in that way:
<input type="hidden" id="var1" name="var1" value="first">
<select id="var2" name="var2">
$("form").submit( function (e)
var url = "something/"+
window.location = url;
However, this solution does not use the URL Manager of Yii and that any change in the URL Manager have no effect on this view.
A possibly improvement to this idea should be to not calculate the variable "url" on client side but to get it through an ajax request to an action which has the task of replacing the classic URL with an URL produced by the URL manager.
This is not the best way but just an idea
November 14, 2012, 10:10am
This solution sounds reasonable. Thank you very much!