2016-07-14 9 views
0

Ich benutze codeigniter 3.0.6 Query-String wieÄndern Sie die MY_Router.php Datei für QUERY STRING Codeigniter 3.0.6

index.php?d=directoryt&c=controller 
index.php?d=directory&c=controller&m=function 

Wie auch immer zwei Methoden erhalten, die für Verzeichnis und Controller ist ein bisschen lang.

Frage Gibt es eine Möglichkeit, die protected function _set_routing() Funktion eine MY_Router.php zu modifizieren indem es zu bekommen, so wird das Verzeichnis und den Controller, indem Sie eine Abfrage nur wie Beispiel unten abholen.

index.php?route=directory/controller 
// If need to get function 
index.php?route=directory/controller&m=function 

Was bisher versucht haben

<?php 

class MY_Router extends CI_Router { 

    protected function _set_routing() 
    { 
     // Load the routes.php file. It would be great if we could 
     // skip this for enable_query_strings = TRUE, but then 
     // default_controller would be empty ... 
     if (file_exists(APPPATH.'config/routes.php')) 
     { 
      include(APPPATH.'config/routes.php'); 
     } 

     if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) 
     { 
      include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); 
     } 

     // Validate & get reserved routes 
     if (isset($route) && is_array($route)) 
     { 
      isset($route['default_controller']) && $this->default_controller = $route['default_controller']; 
      isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes']; 
      unset($route['default_controller'], $route['translate_uri_dashes']); 
      $this->routes = $route; 
     } 

     // Are query strings enabled in the config file? Normally CI doesn't utilize query strings 
     // since URI segments are more search-engine friendly, but they can optionally be used. 
     // If this feature is enabled, we will gather the directory/class/method a little differently 
     if ($this->enable_query_strings) 
     { 
      // If the directory is set at this time, it means an override exists, so skip the checks 

      if (! isset($this->directory)) 
      { 
       $_route = isset($_GET['route']) ? trim($_GET['route'], " \t\n\r\0\x0B/") : ''; 

       if ($_route !== '') 
       { 
        echo $_route; 

        $this->uri->filter_uri($_route); 
        $this->set_directory($_route); 
       } 
      } 



      // Routing rules don't apply to query strings and we don't need to detect 
      // directories, so we're done here 
      return; 
     } 

     // Is there anything to parse? 
     if ($this->uri->uri_string !== '') 
     { 
      $this->_parse_routes(); 
     } 
     else 
     { 
      $this->_set_default_controller(); 
     } 
    } 
} 

config.php

$config['allow_get_array'] = TRUE; 
$config['enable_query_strings'] = TRUE; 
$config['controller_trigger'] = 'c'; 
$config['function_trigger'] = 'm'; 
$config['directory_trigger'] = 'd'; 

// Modifyed in MY_Router.php 
$config['route'] = 'route'; 

Antwort

0

Ich habe es arbeiten

<?php 

class MY_Router extends CI_Router { 

    protected function _set_routing() { 

     if (file_exists(APPPATH.'config/routes.php')) 
     { 
      include(APPPATH.'config/routes.php'); 
     } 

     if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) 
     { 
      include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); 
     } 

     // Validate & get reserved routes 
     if (isset($route) && is_array($route)) 
     { 
      isset($route['default_controller']) && $this->default_controller = $route['default_controller']; 
      isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes']; 
      unset($route['default_controller'], $route['translate_uri_dashes']); 
      $this->routes = $route; 
     } 

     if ($this->enable_query_strings) { 

      if (! isset($this->directory)) 
      { 
       $route = isset($_GET['route']) ? trim($_GET['route'], " \t\n\r\0\x0B/") : ''; 

       if ($route !== '') 
       { 
        $part = explode('/', $route); 

        $this->uri->filter_uri($part[0]); 
        $this->set_directory($part[0]); 

        if (! empty($part[1])) { 

         $this->uri->filter_uri($part[1]); 
         $this->set_class($part[1]); 

         // Testing function atm 
         if (! empty($_GET['function'])) 
         { 
          $this->uri->filter_uri($_GET['function']); 
          $this->set_method($_GET['function']); 
         } 

         $this->uri->rsegments = array(
          1 => $this->class, 
          2 => $this->method 
         ); 
        } 

       } else { 

        $this->_set_default_controller(); 
       } 
      } 

      // Routing rules don't apply to query strings and we don't need to detect 
      // directories, so we're done here 
      return; 
     } 

     // Is there anything to parse? 
     if ($this->uri->uri_string !== '') 
     { 
      $this->_parse_routes(); 
     } 
     else 
     { 
      $this->_set_default_controller(); 
     } 
    } 
}