Welcome Guest, Not a member yet? Register   Sign In
An alternative way to send variables to functions?
#11

[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.
#12

[eluser]adamp1[/eluser]
Code:
$this->load->controller("news",$array);

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

[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.
#14

[eluser]adamp1[/eluser]
@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.
#15

[eluser]KeyStroke[/eluser]
Ok thanks. I guess I'll have to use it then. Smile
#16

[eluser]Lima[/eluser]
Yeah it's possible for you
just do this things :

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

make helpers to easy access like this
Code:
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

http://www.yoursite.com/welcome/home/?va...ar2=value2
Code:
$data = get_request_data(array('var1', 'var2', 'var3'), array('default1', 'default2', 'default3'));

or

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

hope this can help.
#17

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

[eluser]adamp1[/eluser]
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.
#19

[eluser]Lima[/eluser]
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
#20

[eluser]ScottBruin[/eluser]
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.

http://codeigniter.com/wiki/alternative_to_GET/




Theme © iAndrew 2016 - Forum software by © MyBB