How do I encode a query string containing forward slashes?
I need to pass a path as a parameter to a url e.g. /Co开发者_如何学JAVAntroller/Action/My-Path but My-Path contains forward slash e.g. /dir1/dir2/file.php Is there any way of passing this path as a single parameter or do I need to break the path down as /Controller/Action/Param1/dir1/Param2/dir2/Param3/file.php. Some sample code would be appreciated
TIA Ephraim
You can use url view helper, e.g.:
echo $this->view->url(
array(
'controller' => 'somecontroller',
'action' => 'someaction',
'path'=>'/dir1/dir2/file.php')
);
This will result in:
public/somecontroller/someaction/path/%2Fdir1%2Fdir2%2Ffile.php
url view helper automatically uses url_encode to encode your parameters (see other anwser).
See: http://ar2.php.net/url_encode
so you would do:
$param = url_encode("/this/parameter/file");
精彩评论