【问题标题】:Using multiple database and issue with URI Routing on same CodeIgniter 3x application在同一个 CodeIgniter 3x 应用程序上使用多个数据库和 URI 路由问题
【发布时间】:2016-10-02 01:28:45
【问题描述】:

我正在开发一个小型 Web 应用程序。在我的应用程序中,我遵循以下方法。

系统小概览

  1. 应用程序将托管在服务器上,例如 (www.example.com)
  2. 微软、可口可乐、IBM....等客户将注册。客户端将使用这样的 url ( www.example.com/ibm ) 访问应用程序
  3. 每个客户都有单独的数据库来存储他们的数据。
  4. 如果客户的员工想登录系统,那么 url 模式应该是这样的: (www.example.com/ibm/user/login) ibm - 是客户 用户 - 是控制器 login - 是用户控制器的方法

我也问过同样的问题,我修复并发布了答案: CodeIgniter Help - using multiple database on same application and issue with URI Routing

我的解决方案适用于 CodeIgniter 2.X,但不幸的是不适用于 CodeIgniter 3.X。

如何在 CodeIgniter 3.X 中实现这一点?

【问题讨论】:

    标签: php .htaccess codeigniter url-rewriting url-routing


    【解决方案1】:

    我找到了这个解决方案。

    1. 在文本编辑器中打开 system/core/router.php。
    2. 转到第 335 行 .... function _validate_request($segments)
    3. 用此代码替换 _validate_request 函数。

      protected function _validate_request($segments)
      {
          if(count($segments)===1)
          {
              $segments[0]='';
          }
          if(count($segments) > 1)
          {
              $x=$segments;
              $a=1;
              for($i=0;$i<(count($segments)-1); $i++)
              {
                  $segments[$i]=$x[$a];
                  $a++;
              }
              unset($segments[$i]);
          }
          $c = count($segments);
          // Loop through our segments and return as soon as a controller
          // is found or when such a directory doesn't exist
          while ($c-- > 0)
          {
              $test = $this->directory.ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]);
      
          if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0]))
          {
              $this->set_directory(array_shift($segments), TRUE);
              continue;
          }
          return $segments;
      }
      // This means that all segments were actually directories
      return $segments;
      
      }
      

    【讨论】:

    • 应该说最好不要打补丁或修改库的核心,除非你在维护自己的fork。通常,最好创建受影响模块的子类,然后使用提供的任何 DI 解决方案将其注入。 CodeIgniter 允许你这样做吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 2019-08-25
    • 2013-12-05
    相关资源
    最近更新 更多