在同一个 CodeIgniter 3x 应用程序上使用多个数据库和 URI 路由问题
Using multiple database and issue with URI Routing on same CodeIgniter 3x application
我正在开发一个小型网络应用程序。在我的应用程序中,我遵循以下方法。
系统小概览
- 应用程序将托管在服务器上,例如 (www.example.com )
- 微软、可口可乐、IBM等客户将报名参加。客户端将像这样使用 url 访问应用程序 ( www.example.com/ibm )
- 每个客户将有单独的数据库来存储他们的数据。
- 如果客户的员工想要登录系统,那么 url 模式应该是这样的:
(www.example.com/ibm/用户/登录)
ibm - 是客户
用户 - 是控制器
login - 是用户控制器的方法
我问过同样的问题,我修改并发布了答案:
CodeIgniter Help - using multiple database on same application and issue with URI Routing
我的解决方案适用于 CodeIgniter 2.X,但不幸的是不适用于 CodeIgniter 3.X。
如何在 CodeIgniter 中实现这个 3.X?
我找到了这个解决方案。
- 在文本编辑器中打开 system/core/router。php。
- 转到第 335 行 .... 函数 _validate_request($segments)
用此代码替换 _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;
}
我正在开发一个小型网络应用程序。在我的应用程序中,我遵循以下方法。
系统小概览
- 应用程序将托管在服务器上,例如 (www.example.com )
- 微软、可口可乐、IBM等客户将报名参加。客户端将像这样使用 url 访问应用程序 ( www.example.com/ibm )
- 每个客户将有单独的数据库来存储他们的数据。
- 如果客户的员工想要登录系统,那么 url 模式应该是这样的: (www.example.com/ibm/用户/登录) ibm - 是客户 用户 - 是控制器 login - 是用户控制器的方法
我问过同样的问题,我修改并发布了答案: CodeIgniter Help - using multiple database on same application and issue with URI Routing
我的解决方案适用于 CodeIgniter 2.X,但不幸的是不适用于 CodeIgniter 3.X。
如何在 CodeIgniter 中实现这个 3.X?
我找到了这个解决方案。
- 在文本编辑器中打开 system/core/router。php。
- 转到第 335 行 .... 函数 _validate_request($segments)
用此代码替换 _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; }