gunter Posted March 2, 2016 Posted March 2, 2016 I am writing a module and want pass a parameter by the url parameter to an "___executeSomething" method, how can I encode and decode something to pass it in the url?The data contains slashes (it´s a path), so I tried urlencode() and base64_decode() but this seems not to work, because somehow the browser seems to decode it by itself..with urlencode() comes a 404 path not found error...with base64_decode() comes just a blank screen...so what shall I do?
gRegor Posted March 3, 2016 Posted March 3, 2016 If I'm understanding you correctly, I think you can use $this->input->urlSegment1 (2, 3, and so on). within your ___execute* method. I don't think you'd have to worry about any encoding or decoding.
LostKobrakai Posted March 3, 2016 Posted March 3, 2016 The ___execute* functions are already depending on urlSegments. To pass data around rather use GET or POST data.
gunter Posted March 3, 2016 Author Posted March 3, 2016 I know how to pass data to my process module function, $text=wire("input")->urlSegment2 works wonderfully...But my data that I want to pass to my function something like this: "/fullpage3/site/templates/scripts/jquery-2.2.0.js"So.. I just can say you.. an url like this does not work... the url parameter cannot have slashes...As I already mentioned, I wanted encode it, but this did not work with the functions I mentioned... What worked was this: str_replace('/', '---', $weblink) but that looks silly..... Ok, Lostkobrakai, GET parameter did work... but I can use it only withecho ($_GET["link"]); and not withecho $input->get['link']; //this does not work...
gunter Posted March 3, 2016 Author Posted March 3, 2016 ah... Forget to do it like that, I think this should work, thanks Martijn!But I found a solution to do it the way I wanted, in an encoded parameter, it looks a little bit complicated, but it works, I found it at the php documentation at base64_encode at the comments:"Php version of perl's MIME::Base64::URLSafe, that provides an url-safe base64 string encoding/decoding (compatible with python base64's urlsafe methods)" //we are here in a module: public function ___execute() $weblink= "this is the url parameter I want pass! with/my/filepath/file.css"; $weblink = base64_encode($weblink); $weblink = str_replace(array('+','/','='),array('-','_',''),$weblink); $link="<a href='./something/". $weblink."''>open detail</a>"; public function ___executeSomething() { $this->headline('This is something!'); $this->breadcrumb('../', 'Hello'); $url_parameter=wire("input")->urlSegment2; $url_parameter = str_replace(array('-','_'),array('+','/'),$url_parameter); $mod4 = strlen($url_parameter) % 4; if ($mod4) { $url_parameter .= substr('====', $mod4); } $url_parameter=base64_decode($url_parameter); $out = " <h2>".$url_parameter."</h2>"; }
gRegor Posted March 3, 2016 Posted March 3, 2016 What's your use-case for passing a path to jQuery like that, or was it a made up example? base64 enc/de-coding shouldn't be necessary if you're using the get parameters. It might be easier to just pass in the script name "jquery-2.2.0.js" and use $config to build the URLs to the file, though. 1
gunter Posted March 3, 2016 Author Posted March 3, 2016 I wrote a module that scans the template subfolders for javascript and css files and displays them in a list.Each line has an "open detail" link, when you click it, the path and file gets passed to the sub function (the __executeSomething).... The module sub function displays then the proper code and path.... to the files: (the names of the files are examples)<script src="<?php echo $config->urls->templates?>scripts/jquery-2.2.0.js"></script>or<link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/jquery.bxslider.css" />I found it like this better than to do this by hand... I am trying to get confident with modules, I never used GET parameters but it´s a good idea, thanks... I thought using the url parameter is the way to do this ;-)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now