Yii Framework Forum: urlManager with path format and having encoded slashes as parameter - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

urlManager with path format and having encoded slashes as parameter Rate Topic: -----

#1 User is offline   knoo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 22-April 09

Posted 22 April 2009 - 08:43 AM

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?

0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,902
  • Joined: 04-October 08
  • Location:DC, USA

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.
1

#3 User is offline   pommeverte 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 15-March 11

Posted 06 March 2013 - 02:42 PM

I've encountered this issue recently.

We can get rid of the apache 404 issues by adding
AllowEncodedSlashes NoDecode
to 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&param1=value1&param2=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.
0

#4 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 March 2013 - 04:25 PM

It's easy enough to append all the named parameters you want:

'<controller:\w+>/<action:\w+>/<id:\d+>/<country>/<county>/<city>/<street>' => '<controller>/<action>',


As long as you know the parameters beforehand.
"Less noise - more signal"
0

#5 User is offline   pommeverte 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 15-March 11

Posted 06 March 2013 - 05:59 PM

View Postjacmoe, on 06 March 2013 - 04:25 PM, said:

It's easy enough to append all the named parameters you want:

'<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&paramName=param%2Fvalue
// Yii doesn't seem to care for non-path URLs because of main.php config


Do 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.
0

#6 User is offline   redblom 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 14-March 14

Posted 14 March 2014 - 01:29 PM

Hello,
I have to work with parameter values that have slashes in them and encountered the same problem.
The solution I use now is simply replacing '%2F' with '/' in the url returned by createUrl(). Now all parameters and values come through fine. So this works just fine for me right now.
My question is does anybody know if there is a (potential) problem with this solution?
Thanks.
0

#7 User is offline   xiaoxiaoshijie 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 11-June 13

Posted 28 April 2014 - 12:59 AM

How did you solve the problem?
I want to know where in the controller you put the code to?
I have the same problem. Thanks!

--------------------

View Postpommeverte, on 06 March 2013 - 05:59 PM, said:

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&paramName=param%2Fvalue
// Yii doesn't seem to care for non-path URLs because of main.php config


Do 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.

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users