Combine friendly url and query string

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

0
source share
1 answer

This is possible by setting $config['enable_query_strings'] = TRUE; to your config.php file (as DamienL replied). I just tried with a new CodeIgniter installation from here .

However, it looks like there should be at least two variables (separated by "&") to work.

Here are the steps I took to do this:

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

In the controller 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 */ 

Then I can access the index function using the query string, but only if there are two or more variables:

local / CodeIgniter_1.7-1.2 / index.php / testing / Index ID = 123 & cat = ABC

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

+5
source

Source: https://habr.com/ru/post/1310695/


All Articles