• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An alternative way to send variables to functions?

[eluser]Pascal Kriete[/eluser]
Uhhh.... $this->load->controller doesn't exist.

I have no idea what you're trying to do. Can you give a more concrete example, doesn't have to be CI at all. Just a general idea of what you're trying to accomplish and why it needs query strings instead of slashed variables.


what's that? that's not a valid CodeIgniter method. Hooks? there for performing actions before running part of the CodeIgniter system.

[eluser]Jamie Rumbelow[/eluser]
Whatever. I know what I mean in my head. I'l do an example tommorow.

EDIT: Right i've worked it out. Use the $this->load->vars() function in your constructor.

@KeyStroke: Why are you worrying about it being a bit messy? Many many websites use very long url's to pass data. I know I never look at the url apart from the domain name (to check its not a scam). Other than how we said there isn't another way I'm afraid.

Ok thanks. I guess I'll have to use it then. Smile

Yeah it's possible for you
just do this things :

modify config/config.php
$config['permitted_uri_chars'] = '';

make helpers to easy access like this
if (! function_exists('get_request_data'))
  function get_request_data($names, $default=null, $xss_clean=FALSE)
    $rtn = array();
    if (is_array($names)) foreach ($names as $i => $v)
      if (isset($_REQUEST[$v])) $rtn[$v] = $xss_clean ? xss_clean($_REQUEST[$v]) : $_REQUEST[$v];
      else $rtn[$v] = isset($default[$v]) ? $default[$v] : null;
    elseif (isset($_REQUEST[$names])) $rtn = $xss_clean ? xss_clean($_REQUEST[$names]) : $_REQUEST[$names];
    else $rtn = $default;

    return $rtn;

from your controller just call helper

$data = get_request_data(array('var1', 'var2', 'var3'), array('default1', 'default2', 'default3'));


$data = get_request_data('var1', 'default1');

hope this can help.

[eluser]James Pax[/eluser]
use post... so you can have a clean and sexy url Smile

Problem is if he's not using a form (which by the format he's looking at I would think he isn't) POST isn't an option. Uri_to_assoc is the best option.

I think so, uri_to_assoc() is the best option. But sometime when we submit form using GET method browser will generate query string like that. We need to convert query string to CI url style using JavaScript, but sometime some browser does not support JavaScript like elink. and the best way we must using POST method to request to server and redirect it to CI style url.

Sometime I hate using POST method, because when browser need to be refreshed using F5 it prompt dialog box.

My script just another option. Smile

Late to this party but Keystroke, I suggest using the "alternative to GET" helper function which allows URLS like example.com/folder/controller/method/name:joe/id:36043. It looks better than /name/joe/id/36043 and would make more sense to a user.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.