• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URI_Helper

#1
[eluser]Chris Newton[/eluser]
I miss the ease & simplicity of query strings, and I don't like using numbered segments to grab data out of the URI string. I wrote a simple helper to make getting & setting key=>value pairs in the URI using the URI library.

http://codeigniter.com/wiki/URI_helper/

#2
[eluser]xwero[/eluser]
I don't see the benefit of this helper? There are not so many lines in the methods and you are using the CI uri functions. For instance the get_uri method is not more code than
Code:
$get = $this->uri->uri_to_assoc(3);
if(isset($get[$key]))
{
   // do something with the value
}

I also think you can join the set_uri and set_uri_array like other functions of CI
Code:
function set_uri($data,$value=null)
{
   $array = array();
   if(is_array($data))
   {
       foreach ($data as $key => $val ){
         $array[$key]=$val;
        }
   }
   elseif(is_string($data) && $value !== null)
   {
     $array[$data]=$value;
   }
   else
   {
     return false;
   }
   return $this->uri->assoc_to_uri($array);
}

edit : if you have helpers like this you could create an extended CI class in the application/libraries directory so you don't have to autoload it.

#3
[eluser]Chris Newton[/eluser]
As I mentioned in the wiki... it doesn't cut down on too much, but some. It's not unlike some other CI helpers, for instance br(n); which I use all the time from the HTML helper. If it cuts down on a few keystrokes that's what it's designed to do.

Don't like it? Don't use it.

#4
[eluser]sikkle[/eluser]
good works.

#5
[eluser]Chris Newton[/eluser]
Oh, and before I forget, I just wanted to thank xwero for the input. The method you describe for set_uri is a good one, and probably better for many people. For my own sake however, I like using 2 different functions for arrays & for single pairs. It may be silly, but it just helps me mentally keep track of what I'm setting.

#6
[eluser]xwero[/eluser]
Nothing is silly we all have are own way of coding.

I'm actually beginning to like the get_uri method, i even think about adding it to my MY_URI library.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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