CodeIgniter Forums
Codeigniter URL Pattern using htaccess / route / model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Codeigniter URL Pattern using htaccess / route / model (/showthread.php?tid=63834)



Codeigniter URL Pattern using htaccess / route / model - Codeigniter_Learner - 12-13-2015

I've just put my hands on MVC and new to Codeigniter.

As per my understanding Codeigniter url consist of (base url) / Class / Method

I am trying some more complex url structure as
base_url/listing/category/country/state/city/listing-id-23
which I presume can be achieved by calling another controller from another, or may be using route.

PS, category/country/state/city here changes dynamically based on product.

Is it possible to have url like that with Codeigniter or do I have to stick with www.example.com/listing/listing-id-23 ?
Thanks you.


RE: Codeigniter URL Pattern using htaccess / route / model - Martin7483 - 12-14-2015

Yes, you can have an URL like that. How is up to you.

An option is to use the _remap method

Add this to your controller
PHP Code:
public function _remap($method) {
 
   // $method = typically the second segment of the URI
 
   if ($method === 'some_method') {
 
       $this->$method();
 
   } else {
 
       $this->what_ever_method();
 
   }


What this does is override the default behavior of how CI calls methods. When this method is available within the called controller this is the first method called.
From here you can route to any other method within the called controller.

If you want controllers calling controllers how should look into HMVC
But if you are new to MVC and CI I would advise getting to know the basics first.

Hope this helps you on your way