I have url manager with friendly url:s and I use htaccess to hide index.php
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
),
Now when I create url with parameter containing slashes:
$this->createUrl('site/doit', array("param"=>"/example/path"))
I get url like "http://localhost/site/doit/param/%2Fexample%2Fpath"
which apparently is not valid url for apache and I get 404 directly.
(See for example: http://www.webmaster...he/3279075.htm)
By encoding the parameters twice it is possible to get working url with %252f, but Yii isn't doing that, and I'm not even sure if thats a good workaround.
Anyway looks like, the path format doesn't work with params that has slashes, am I correct or am I just doing something wrong?
Page 1 of 1
urlManager with path format and having encoded slashes as parameter
#2
Posted 22 April 2009 - 09:44 AM
You are right that you can't have slashes in GET params when using path format. It is impossible for Yii to correctly resolve the request.
#3
Posted 06 March 2013 - 02:42 PM
I've encountered this issue recently.
We can get rid of the apache 404 issues by adding
http://stackoverflow...ashes-on-apache
But like qiang says, Yii will just treat it as a forward slash which doesn't help.
So I was wondering if there was anyway we might be able to force the urlmanager to not use path format in specific situation.
I've tried using Yii::app()->urlManager->urlFormat = "get"; as well as Yii::app()->urlManager->showScriptName = true; But all I ever get frome create(Absolute)Url() is something along the lines of
If it were just a matter of creating a single url i could use createPathInfo but the issue is when you are using CGridView for example it would be nice to have an easy way to have pagination and the likes switch to "get" rather than "path" format.
Let me know if anyone has a solution to this.
We can get rid of the apache 404 issues by adding
AllowEncodedSlashes NoDecodeto the apache Virtual Host (or check link for apache config and other bugs)
http://stackoverflow...ashes-on-apache
But like qiang says, Yii will just treat it as a forward slash which doesn't help.
So I was wondering if there was anyway we might be able to force the urlmanager to not use path format in specific situation.
I've tried using Yii::app()->urlManager->urlFormat = "get"; as well as Yii::app()->urlManager->showScriptName = true; But all I ever get frome create(Absolute)Url() is something along the lines of
http://my.domain/?r=controller/action¶m1=value1¶m2=value2&...which does not redirect to controller/action as it should (it will just load the site index).
If it were just a matter of creating a single url i could use createPathInfo but the issue is when you are using CGridView for example it would be nice to have an easy way to have pagination and the likes switch to "get" rather than "path" format.
Let me know if anyone has a solution to this.
#4
Posted 06 March 2013 - 04:25 PM
It's easy enough to append all the named parameters you want:
As long as you know the parameters beforehand.
'<controller:\w+>/<action:\w+>/<id:\d+>/<country>/<county>/<city>/<street>' => '<controller>/<action>',
As long as you know the parameters beforehand.
"Less noise - more signal"
#5
Posted 06 March 2013 - 05:59 PM
jacmoe, on 06 March 2013 - 04:25 PM, said:
It's easy enough to append all the named parameters you want:
As long as you know the parameters beforehand.
'<controller:\w+>/<action:\w+>/<id:\d+>/<country>/<county>/<city>/<street>' => '<controller>/<action>',
As long as you know the parameters beforehand.
Well the problem here is that a dynamic form is used to run a search on content. This form sends the data as GET, and slashes are allowed (in say, searching dates). I do not know beforehand how many fields are going to be sent or which ones they are, but I do have to handle slashes in params.
Obviously this is an issue with 'path' format urls, but If I want to switch to 'get' format urls for this request as well as all pager links (in cgrid and clist), but keep path format for the rest of the site, I hit a bit of a wall.
I was wondering if there was anyway to switch from one to the other on demand. Just setting the urlManager->urlFormat to "get" dynamically gives me an url when I createUrl() that isn't interpreted correctly by Yii on the other end.
Just so we're clear:
My main.php is configured as follows:
'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName' => false, ...
In a controller:
echo $this->createUrl('controller/action',array('paramName'=>'param/value')); // working url of /controller/action/paramName/param%2Fvalue
// but as mentioned above, Yii treats %2F as a slash so my GET is corrupt
Yii::app()->urlManager->urlFormat = 'get'; //or Yii::app()->urlManager->setUrlFormat('get');
Yii::app()->urlManager->showScriptName = true;
echo $this->createUrl('controller/action',array('paramName'=>'param/value')); //non-working ?r=controller/action¶mName=param%2Fvalue
// Yii doesn't seem to care for non-path URLs because of main.php configDo you guys see any easy solution for this? a 'get' url that would work would be /controller/action?paramName=param%2FValue but the URL manager does not create urls like this oddly. I was hoping we could get another urlFormat. Is there a way of setting up a custom one? I could then hopefully configure the pager's urlmanager options.
Share this topic:
Page 1 of 1

Help












