开发者

Codeigniter - Dynamic Routing from Hook

开发者 https://www.devze.com 2023-02-18 04:55 出处:网络
I am dynamically generating the top level navigation from a hook and I want to dynamically add routing based with the \"permalinks\" column in the database.

I am dynamically generating the top level navigation from a hook and I want to dynamically add routing based with the "permalinks" column in the database.

Is there anyway to dynamically add to the $route variable fro开发者_StackOverflow社区m a hook?

Thanks.


If you had a URL structure like this,

site.com/controller/navigation_link_item

where navigation_link_item is coming from a database, then within the controller you can access the second part of the URL like this:

$this->uri->segment(2);

You can then use this to lookup the database.

Depending on the situation and how you have setup your .htaccess, it may be necessary to route the secondary pages to the main controller. In routes.php you need to add a line similar to this:

$route['controller/:any'] = 'controller';

This will route all URLs with controller/ at the beginning to your controller so you can see if it matches a page in your database. If you don't have an entry for the incoming URI segment, you can give a 404 error:

show_404();


Default routing is

$this->uri->segment(3);

But you can set as per your requirement. and depends on url

like

test.com/youtcontroller/aboutfunction

 $this->uri->segment(2);
0

精彩评论

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