Welcome Guest, Not a member yet? Register   Sign In
Getting CodeIgniter to work with URL parameters site,com/controller/method/?param=value
#2

[eluser]CtheB[/eluser]
There is no reason you need to work with parameters.
Tell me just 1 valid reason.

You can use the "parameters" like segments as follow:

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_URI extends CI_URI {
    
    public function __construct()
    {
        parent::CI_URI();
    }
    
    public function segment($n, $no_result = FALSE)
    {
        if(is_string($n) && ($key = array_search($n,$this->segments)) !== false)
        {
            $n = $key+1;
        }
        return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n];
    }

    public function rsegment($n, $no_result = FALSE)
    {
        if(is_string($n) && ($key = array_search($n,$this->rsegments)) !== false)
        {
            $n = $key+1;
        }
        return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n];
    }

    public function slash_segment($n, $where = 'trailing')
    {
        if(is_string($n) && ($key = array_search($n,$this->segments)) !== false)
        {
            $n = $key+1;
        }
        return $this->_slash_segment($n, $where, 'segment');
    }
    
    public function slash_rsegment($n, $where = 'trailing')
    {
        if(is_string($n) && ($key = array_search($n,$this->rsegments)) !== false)
        {
            $n = $key+1;
        }
        return $this->_slash_segment($n, $where, 'rsegment');
    }
}

Now you can use $this->uri->segment("param") // This will give back "value"


Messages In This Thread
Getting CodeIgniter to work with URL parameters site,com/controller/method/?param=value - by El Forum - 12-09-2009, 06:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB