CodeIgniter Forums
mixing URI query and URI Segment - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: mixing URI query and URI Segment (/showthread.php?tid=7308)



mixing URI query and URI Segment - El Forum - 04-03-2008

[eluser]tominku[/eluser]
CI's uri convention is class/function/parameter1/parameter2

but is it possible to use like this?

http://my_site.com/index.php/blog/write/name=kang&subject=hi&memo=blah

but it wasn't work.. i saw "invalid URI" message

in fact, it is inconvenient to just depend on the sequence of parameter like this

URI: blog/write/kang/hi/blah
USAGE:
Code:
class Blog extends Controller{
        function write($name, $subject, $memo){
             ...some db related working.....
        }
    }



mixing URI query and URI Segment - El Forum - 04-03-2008

[eluser]xwero[/eluser]
you can do http://my_site.com/index.php/blog/write/name/kang/subject/hi/memo/blah. But i hope you understand the limits of the query string approach. Those values you attach to the url should be posted.

Said that you can extract the url as follows
Code:
$params = $this->uri->uri_to_assoc(3);
// which gives you
array('name'=>'kang','subject'=>'hi','memo'=>'blah')



mixing URI query and URI Segment - El Forum - 04-03-2008

[eluser]tominku[/eluser]
so... is it possible to use like this?
http://my_site.com/index.php/blog/write/name=kang&subject=hi&memo=blah

it brings out the message "The URI you submitted has disallowed characters."


mixing URI query and URI Segment - El Forum - 04-03-2008

[eluser]xwero[/eluser]
I think it works if you do http://my_site.com/index.php/blog/write/?name=kang&subject=hi&memo=blah and set the enable_query_string to true in the config file. But then you have to get the values using $_GET['name'] or $this->input->get('name')


mixing URI query and URI Segment - El Forum - 04-03-2008

[eluser]tominku[/eluser]
thank you very much!
i set enable_query_string to true, then it works!

but there is some bug..

http://localhost:8888/codeigniter/index.php/blog/getList/?name=kang&subject=hi
it works. but...

http://localhost:8888/codeigniter/index.php/blog/getList/?name=kang
(bring out the message "The page you requested was not found.")
i think the number of parameters should be at least two..


mixing URI query and URI Segment - El Forum - 04-03-2008

[eluser]xwero[/eluser]
Yes you are right that is because of following code in the _fetch_uri_string in the uri library
Code:
if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
        {
            // If the URL has a question mark then it's simplest to just
            // build the URI string from the zero index of the $_GET array.
            // This avoids having to deal with $_SERVER variables, which
            // can be unreliable in some environments
            if (is_array($_GET) AND count($_GET) == 1)
            {
                $this->uri_string = key($_GET);            
                return;
            }



mixing URI query and URI Segment - El Forum - 09-23-2008

[eluser]Jonathon Hill[/eluser]
So is this a bug?

Code:
// If the URL has a question mark then it's simplest to just
// build the URI string from the zero index of the $_GET array.
// This avoids having to deal with $_SERVER variables, which
// can be unreliable in some environments
if (is_array($_GET) AND count($_GET) == 1 AND trim(key($_GET), '/') != '')
{
    $this->uri_string = key($_GET);            
    return;
}

Since when does $_GET contain the URI string?? This doesn't appear to work at all - is it a bug? What am I missing?