• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
use hook to set CI router

#1
[eluser]Unknown[/eluser]
Dear ALL,
Do not know the two kinds of ways to see the CI route is how to play my impression
1.config/routes.php manually add
2.Gocart type
Code:
include('database.php');

if($db[$active_group]['pconnect'])
{
        mysql_pconnect($db[$active_group]['hostname'],$db[$active_group]['username'],$db[$active_group]['password']);        
}
else
{
        mysql_connect($db[$active_group]['hostname'],$db[$active_group]['username'],$db[$active_group]['password']);        
}
mysql_select_db($db[$active_group]['database']) or die("Unable to select database");

$routes        = mysql_query('SELECT * FROM '.$db[$active_group]['dbprefix'].'routes');

while($row = mysql_fetch_array($routes))
{
        //if "category" is in the route, then add some stuff for pagination
        if(strpos($row['route'], 'category'))
        {
                $route[$row['slug']] = $row['route'];

                $row['slug']         .= '/(:num)';
                $row['route']         .= '/$1';
        }
        $route[$row['slug']] = $row['route'];
}
Tonight, I suddenly found that, routing can be set up
1.Modify CI_Route
Code:
/*add set*/
        public function set($key, $value)
        {
                if ( ! isset($this->routes[$key]))
                {
                        $this->routes[$key] = $value;
                }
        }      


/*_set_routing assign value use self::set function*/
                $routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
                
                if (count($routes) > 0)
                {
                        foreach ($routes as $key => $value)
                        {
                                self::set($key, $value);
                        }
                }
2.congif hook
Code:
$hook['pre_system'] = array(
                                'class'    => 'bootstrap',
                                'function' => 'route_setup',
                                'filename' => 'bootstrap.php',
                                'filepath' => '.');
3.add file bootstrap.php location APPPATH.'bootstrap.php'
Code:
class bootstrap
{
        public function __construct()
        {      
        }
        /*config route */
        public function route_setup()
        {
                /*add route*/
                 $RTX = & load_class('Router', 'core');
                 $RTX->set($key,$value);
        }
}
Any time you want to modify the routing to direct calls


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.