Welcome Guest, Not a member yet? Register   Sign In
unlikely...
#6

I use a key:value pair in my URI to distinguish required variables.
It looks like this: http://www.yourwebsite.com/controller/me...ar_id:1234

For this I have extended the core URI class and have a method that searches for key:value pairs in each available uri segment.
If a segment is a key:value pair, it is removed from the segments array, and I rebuild the URI segments array.

The found pairs are stored in an array params.
So your webinar_id would be stored as:
PHP Code:
$this->params['webinar_id'] = 1234

Below are the methods that I use.

Find the key:value pairs
PHP Code:
/**
 * Method to extract key:value params from the url
 */
private function _set_params() {
 
   if(count($this->segments) > 0) {
 
       foreach($this->segments as $key => $segment) {
 
           ifstrpos($segment':') ) {
 
               list($key_name$value) = explode(':'$segment);
 
               if(is_numeric($value)) {
 
                   $this->params[$key_name] = (int)$value;
 
               } else {
 
                   $this->params[$key_name] = $value;
 
               }
 
               $this->_unset($key);
 
           }
 
       }
 
   }


Reset the URI segment array

PHP Code:
/**
* Method to reindex the segments array after any unset()
*/
private function _unset($key) {
   // Check if the key exists in the segments array
   ifarray_key_exists($key$this->segments) ) {
       // Unset the passed key
       unset($this->segments[$key]);

       // re-index the segments array
       $nkey 1;
       $segments $this->segments;
       $this->segments = array();
       foreach($segments as $segment) {
           $this->segments[$nkey] = $segment;
           $nkey++;
       }
    }


Get all available parameters

PHP Code:
/**
* Return the set parameters
*/
public function get_params() {
   return $this->params;


Get a specific parameter

PHP Code:
/**
 * Return a set param
 */
public function get_param($key) {
 
   ifarray_key_exists($key$this->params) ) {
 
       return $this->params[$key];
 
   }
 
   return NULL;


To get the value of webinar_id in your controllers method, or any method in any class just do:
PHP Code:
$webinar_id $this->uri->get_param('webinar_id'); 

All of the above methods are placed in the extended core URI class MY_URI

Hope this can help you out
Reply


Messages In This Thread
unlikely... - by Rashid - 12-29-2015, 10:11 AM
RE: unlikely... - by mwhitney - 12-29-2015, 10:30 AM
RE: unlikely... - by Rashid - 12-30-2015, 01:25 AM
RE: unlikely... - by mwhitney - 12-30-2015, 09:14 AM
RE: unlikely... - by cartalot - 12-30-2015, 06:56 PM
RE: unlikely... - by Martin7483 - 12-31-2015, 03:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB