我在codeigniter上有一个配置项叫做$config['system_installed'] = TRUE;
或$config['system_installed'] = FALSE;
使它重定向到库中的服务器子文件夹的最佳方法是什么?例如SERVERURI "/" 'install'
设置$config['system_installed'] = FALSE;
将重定向到SERVERURI "/" 'install/index.php'
据我所知:
- 安装过程更新CodeIgniter
config.php
文件,设置$config['system_installed'] = TRUE;
/install
URI是一个目录,它有自己的应用程序,独立于CodeIgniter如果你必须这样做,在application/core
中创建一个名为MY_Controller.php
的基本控制器:
class MY_Controller extends CI_Controller {
function __construct()
{
parent::__construct();
if ( ! config_item('system_installed')) redirect('install');
}
}
你必须将所有控制器更新为ControllerName extends MY_Controller {}
你甚至可以在配置文件中做重定向(作为唯一的内容),如果你要替换它的整个内容。它很脏,但谁在乎呢,这个文件只会在你安装应用程序的时候存在几分钟。
我想建议一个更简单的方法。忘了$config['system_installed']
吧。
在你的根index.php
,只是重定向到/install
,有它是唯一的代码:
<?php
header('Location: install');
exit;
然后让您的安装过程使用实际的CodeIgniter index.php
内容更新index.php
,而不是更新配置文件。在安装目录的某个地方保留一个CI index.php的虚拟副本(无论名称如何),并将内容复制到PHP,然后您甚至可以在安装后自毁/install
。