本文介绍了代码点火器动态路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用代码点火器。

I am using code igniter.

我想做的是

如果页面是

然后我要首先检查一个数据库,看看数据库中是否有 idontexist

Then I want to first check a database to see if idontexist is in the database.

如果是,那么我想将用户路由到

If it is then I want to route the user to

我该怎么做?

推荐答案

一种解决方案是在application / core / MY_Router.php中使用您自己的类扩展CI_Router类,然后在类中复制方法_set_routing()。
您的更改将在包含route.php文件并将其设置为$ this-> routes属性之后进行,您可以添加自定义路由。

One solution would be to extend the CI_Router class with your own in application/core/MY_Router.php and just copy the method _set_routing() in your class.Your changes would go somewhere after routes.php file is included and set to $this->routes property, you can add your custom routes.


include(APPPATH.'config/routes'.EXT);
...
$this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
unset($route);

//Get your custom routes:
$your_routes = $this->_get_custom_routes();
foreach($your_routes as $custom_route)
{
    $this->routes[$custom_route['your_regex_match']] = $custom_route['controller'].'/'.$custom_route['action'];
}

当然您可能不需要,但是我希望它能给您一些想法。
这样,您可以添加自定义路由,并且由于必须从数据库中获取它们,因此可以考虑对其进行缓存以提高速度。

Of course you might not need this, but I hope it gives you some idea.This way you can add custom routes and since you will have to fetch them from database, consider caching them for better speed.

这篇关于代码点火器动态路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 02:39