CI相关设置
一、设置全局调试函数
打开system/core/Common.php
/**
* 自定义全局函数
*/
function p($arr){
echo '<pre>';
print_r($arr);
echo '</pre>';
}
/**
* 成功函数
* @param $url跳转地址
* @param $msg提示信息
*/
function success($url,$msg){
header('Content-Type:text/html;charset=utf-8');
$url=site_url($url);
echo "<script type='text/javascript'>alert('$msg');location.href='$url'</script>";
die;
}
/**
* 错误提示函数
* @param $msg提示信息
*/
function error($msg){
header('Content-Type:text/html;charset=utf-8');
echo "<script type='text/javascript'>alert('$msg');Window.history.back()</script>";
die;
}
/**
* 打印常量
*/
function print_const()
{
$const=get_defined_constants(TRUE);
p($const['user']);
}
二、url上隐藏入口index.php文件
- apache服务器设置:
与入口文件index.php同级目录建立.htaccess
文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
或者
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
- nginx服务器设置:
编辑nginx.conf或者vhost.conf,在server里添加
location / {
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
##或者改成下面也可以
#if (!-e $request_filename) {
# rewrite ^(.*)$ /index.php?$1 last ;
# break;
#}
}
或者
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* \.(db3|json)$ {
deny all;
}
location ~* ^/(temp|upload|imgs|data|application|static|system)/.*.(php|php5)$ {
return 403;
}
三、更改view文件夹位置
在/application/core/
下新建文件MY_Loader.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Loader extends CI_Loader{
public function __construct(){
parent::__construct();
$this->_ci_view_paths = array(FCPATH.'/theme/'=> TRUE);
}
//开启新的视图目录
public function switch_view_on()
{
$this->_ci_view_paths = array(FCPATH . '/theme/' =>true);
//print_r($this->_ci_view_paths);
}
//关闭新的视图目录
public function switch_view_off()
{
#just do nothing
}
}
四、更改application
、system
文件夹名称
打开根目录入口文件index.php
,设置如下:
$system_path = 'system';
$system_path = 'sys';
//$application_folder = 'application';
$application_folder = 'app';
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。