这次顺便做了一个install.php
才发现难度其实并不大,还是文件写入操作而已,安装其实主要操作的还是数据库里的内容,先来看看文件里怎么写:(还是用的Codeigiter,对于使用其他框架或者手写而言,仅思路可参考,用了挺多CI自带的helper
或者是library
的)
$content = "<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');\n";
$content .= '$active_group'. "= 'default';\n";
$content .= '$active_record'." = TRUE;\n";
$content .= '$db'."['default']['hostname'] = '".$this->input->post('hostname')."';\n";
$content .= '$db'."['default']['username'] = '".$this->input->post('rootname')."';\n";
$content .= '$db'."['default']['password'] = '".$this->input->post('pass')."';\n";
$content .= '$db'."['default']['database'] = '".$this->input->post('book')."';\n";
$content .= '$db'."['default']['dbdriver'] = 'mysql';\n";
$content .= '$db'."['default']['dbprefix'] = '';\n";
$content .= '$db'."['default']['pconnect'] = TRUE;\n";
$content .= '$db'."['default']['db_debug'] = TRUE;\n";
$content .= '$db'."['default']['cache_on'] = FALSE;\n";
$content .= '$db'."['default']['cachedir'] = '';\n";
$content .= '$db'."['default']['char_set'] = 'utf8';\n";
$content .= '$db'."['default']['dbcollat'] = 'utf8_general_ci';\n";
$content .= '$db'."['default']['swap_pre'] = '';\n";
$content .= '$db'."['default']['autoinit'] = TRUE;\n";
$content .= '$db'."['default']['stricton'] = FALSE;";
在文件里用\n
来换行,因为里面包括了PHP的代码,这导致了我们只能用双引号避免冲突(否则的话就得用\
了,感觉工作量更大),针对$db
,直接显示必须要用单引号,于是就出现了这个。
- 阅读剩余部分 -