• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Alternate URI syntax

#11
[eluser]codex[/eluser]
I'm using this function:

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

It looks like the same thing, just a lot less code ;-)

#12
[eluser]Colin Williams[/eluser]
I'm just not sure where uri_to_assoc fails? Looks like you just replaced / with :

#13
[eluser]TheFuzzy0ne[/eluser]
The purpose of the library is so that you can pass parameters through the URI, without having to put them in a certain order. For example, take a search function. There could easily be at least 5 different parameters, which may be optional. Using uri_to_assoc just seems too hit-and-miss to me. If the user removes a single segment, the entire associative array will be messed up.

You're right. I have essentially replaced '/' with ':'. In fact, I actually use a ':' instead of a '=', like you see in query strings. By replacing the slash with a colon, it makes it easier to treat the parameters as segments, and identify a key/value pair.

#14
[eluser]TheFuzzy0ne[/eluser]
[quote author="codex" date="1237610559"]I'm using this function:

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

It looks like the same thing, just a lot less code ;-)[/quote]

Hi. I've never seen this helper before. Although the fact that it works in a similar fashion to mine makes me happy that I was on the right track.

You're right, though. It's quite similar to what I started with, I just felt that I should be able to work with the uri object, just like we can in CodeIgniter.

Here's where my library differs:

My library generates the associative array once only, and it does it automatically.

My library allows you to specify a default value if the segment you're after does not exist.

You don't have to work with an array, so no messing with "isset()", the library returns FALSE if you're calling upon a segment that doesn't exist.

My library also allows you to create a custom URL easily from an associative array. Granted, you can probably do this manually just as easily, but it just made sense to me to have a method that created URLs, as well as one that dis-assembled them.

My library automatically urlencode()s strings that are to be send via get. For those who have problems with the server decoding forward slashes automatically, you can use my [url="http://ellislab.com/forums/viewthread/107741/"]URI-safe base64 encode/decode helpers[/url].

Thanks for your comments.

#15
[eluser]xwero[/eluser]
When i discovered the $_SERVER['QUERY_STRING'] isn't touched i need solutions like this even less than i did before. These are all ways to patch the missing GET functionality. Clean urls are nice but sometimes there are more an obstruction than a blessing.

Using GET you don't need to use base64 encode/decode, you don't need to separate the keys from the values, the creation of the url is done by sending form.

If people use this solution i'm not going to stop them, they will have their reasons. I just want to make them aware of the less resource needing alternative

#16
[eluser]TheFuzzy0ne[/eluser]
OK, I should have pointed out earlier that this library is not intended to be a replacement for GET. I designed this because a single method of my application (a search function) accepts multiple optional parameters that could be in any given order. I wanted to make searches bookmarkable, and I didn't want to have to make the Web site use query strings on account of a single function call. My library helps with these situations.

What I'm saying is that, sure, whilst query strings are plain f'ugly, they do give you undeniable flexibility with regards to the order of the parameters you supply. My library is a bridge between both query strings, and segmented URIs. It allows you to utilise one of the best features of query strings, and still allows you to keep your URLs looking clean. It's not a replacement for query strings, but rather a supplement for segmented URIs. It's not necessarily meant to be used in every URL, but those URLs where you need more flexibility.

Thanks for your comments.

#17
[eluser]freshface[/eluser]
How would my controller look like to fetch these params?

#18
[eluser]TheFuzzy0ne[/eluser]
You'd use $this->uri->asegment('key_name');

So if you're URI looked something like this:

http://yoursite.tld/some_controller/some...e/sex:male

then:
Code:
$username = $this->uri->asegment('username');
$sex = $this->uri->asegment('sex');

should do the trick.

Does that help?

#19
[eluser]freshface[/eluser]
This helps for sure.
But it doesn't echo my value:

Code:
<?php

class Welcome extends Controller {

    function __construct()
    {
        parent::Controller();    
    }
    
    function testing()
    {    
        //echo 'remap';
        echo $this->uri->asegment('keyword');
    
    }
}

My url: http://localhost:8888/orange/backend/index.php/welcome/testing/keyword:test

I dont get any errors.

#20
[eluser]TheFuzzy0ne[/eluser]
Hmm, you may have discovered a bug. What happens when you use this URL:

http://localhost:8888/orange/backend/index.php/welcome/testing/keyword:test/other_var:some_val

using the same code?

It might also be worth doing a var_dump() on the return value.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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