views:

179

answers:

1

How to make working such url: example.com/controller/method?id=1&cat=2

+1  A: 

It is possible by setting $config['enable_query_strings'] = TRUE; in your config.php file (As DamienL answered). I just tried with a fresh CodeIgniter installation from here.

However, it appears there must be at least 2 variables (separated with a "&") for it to work.

Here are the steps I took to make this happen:

  1. In config.php, I changed $config['base_url'] to the appropriate directory
  2. Also, in config.php I set $config['enable_query_strings'] = TRUE;
  3. In the controllers directory I created the following class:

    class Testing extends Controller {

    function Testing()
    {
        parent::Controller();   
    }
    
    
    function index()
    {
        $this->load->view('welcome_message');
    }
    

    }

/* End of file testing.php */

/* Location: ./system/application/controllers/testing.php */

I can then access the index function with a query string, but only if there are 2 or more variables like this:

localhost/CodeIgniter_1.7-1.2/index.php/testing/index?id=123&cat=abc

Here is the screenshot (here is the full-size version):

alt text

If you absolutely need both the segment-based and query string-based approaches, but only need one variable in a particular query string, I suppose you could add a second "dummy" variable and just ignore it.

Colin
dynback.com
@dynaback.com: Why the -1? After enabling query strings, you *can* do 127.0.0.1/critic/index.php/testing/index?some=1. I'll edit my answer to clarify
Colin
I have 404 for this. When I set that option, only-segment and only-query-string become working. But not both in one url.
dynback.com
@dynback.com: I modified my answer to provide a more precise explanation (Note the part regarding the two query string variables). Also, did my response really warrant a -1?
Colin
yes, you really solved it. But in any case, why cant I put one query parameter ... strange
dynback.com
@dynback.com: Strange indeed - I'm not sure why that is. Glad you got it working though!
Colin