开发者

Combine friendly url and query string [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it 开发者_高级运维can be reopened, visit the help center. Closed 10 years ago.

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


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:

In config.php, I changed $config['base_url'] to the appropriate directory and set $config['enable_query_strings'] = TRUE;

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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜