URL encoding
Permalink
Hi,
I'm not familiar with c5 and I can't get my parameters to pass from my page to my controller properly.
My setup:
I have a page named item.php under /single-pages and the controller under /controllers:
class itemController extends Controller {
public function item($url,$xx,$pp,$tt){
$this->set('url',$url);
$this->set('xx',$xx);
$this->set('pp',$pp);
$this->set('tt',$tt);
}
}
Single page:
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<h1><?php echo t('Test')?></h1>
<div id='mydiv'>
<?php
$test = urlencode('http://blelbe.com');
$xtest = urlencode('//qsdsqd/qsd');
?>
<a href="<?php echo $this->url('/item','test', $test,$xtest,'25343','blabla blabla') ?>">test1!</a>
<a href="<?php echo $this->url('/item','test', 'http://blelbe.com','//qsdsqd/qsd',$ptest,'blablabla blabla') ?>">test2!</a>
<h2>Liste des params:</h2>
<?php echo $url; ?><br/>
<?php echo $xx; ?><br/>
<?php echo $pp; ?><br/>
<?php echo $tt; ?><br/>
</div>
The first link is not working, the page is not found when I encode the parameters.
For the second link the parameters are wrong due to the forward slashes:
$url=http:
$xx=blelbe.com
$pp=qsdsqd and so on.
I know my question is ridiculous but I don't understand why encoding the parameters don't solve my issue.
I'm not familiar with c5 and I can't get my parameters to pass from my page to my controller properly.
My setup:
I have a page named item.php under /single-pages and the controller under /controllers:
class itemController extends Controller {
public function item($url,$xx,$pp,$tt){
$this->set('url',$url);
$this->set('xx',$xx);
$this->set('pp',$pp);
$this->set('tt',$tt);
}
}
Single page:
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<h1><?php echo t('Test')?></h1>
<div id='mydiv'>
<?php
$test = urlencode('http://blelbe.com');
$xtest = urlencode('//qsdsqd/qsd');
?>
<a href="<?php echo $this->url('/item','test', $test,$xtest,'25343','blabla blabla') ?>">test1!</a>
<a href="<?php echo $this->url('/item','test', 'http://blelbe.com','//qsdsqd/qsd',$ptest,'blablabla blabla') ?>">test2!</a>
<h2>Liste des params:</h2>
<?php echo $url; ?><br/>
<?php echo $xx; ?><br/>
<?php echo $pp; ?><br/>
<?php echo $tt; ?><br/>
</div>
The first link is not working, the page is not found when I encode the parameters.
For the second link the parameters are wrong due to the forward slashes:
$url=http:
$xx=blelbe.com
$pp=qsdsqd and so on.
I know my question is ridiculous but I don't understand why encoding the parameters don't solve my issue.
try addslashes()
thank you for your answer but it doesn't help as addslashes add backslashes to quotes or backslashes.
I actually had trouble doing this a while back, I just ended up doing base64_encode and decode
Instead of using encode64 I'll do my own encoding/decoding function to replace only slashes by a code because I'll get the parameters from a bookmarklet and javascript hasn't any encode64 function.
Anyway thanks for your help!
Anyway thanks for your help!
That's not right. You can use base64encode or decode with Javascript.
A little jquery plugin:
http://plugins.jquery.com/files/jquery.base64.js_1.txt...
A little jquery plugin:
http://plugins.jquery.com/files/jquery.base64.js_1.txt...
Yeah that's right but there is a limit to the number of characters a bookmarklet can contain, and mine is already quite heavy :P
Try using rawurlencode ?