搭建CodeIgniter开发环境

来源:互联网 发布:爱奇艺mac离线下载 编辑:程序博客网 时间:2024/05/21 07:03

第一章 搭建CodeIgniter开发环境

 

php工程

 

使用IDE

 

 

 

第一步:

 

 

 

 

第二步:

 

 

 

 

 

第三步:

 

 

 

 

 

目录树

新建工程时,IDE

 

 

 

 

 

新建工程时,本地磁盘

 

 

-----------------------------------------------------xiaobin_hlj80--------------------------------------------- 

 

使用CodeIgniter

CI文件夹说明:

 

(1)   application

我们开发时放置文件的

Application-

               +----cache

        +---config

        +----controllers

        +----core

               +----errors

        +----helpers

        +----hooks

        +----language

        +----libraries

        +----logs

        +----migrations

        +----models

        +----third_party

        +----views

 

 

蓝色字体:

辅助用文件夹。

Config主要为配置之用。

Helper主要为页面辅助函数。

 

红色字体:

Controllers具体工作的控制器

Model具体工作的模型

Views具体工作的视图

 

红底部分:

Core: 控制器与模型基类

Libraries: 控制器或模型的继承类

 

(2)   system文件夹

CI提供的,一般不建议修改。

 

 

 

拷贝CI到工程根目录

 

 

 

 

 

在工程中新建文件夹public_html

 

 

 

 

 

 

 

 

 

 

把index.php移到public_html中

 

 

变更index.php中的路径:

 

 

 

 

 

 

(一)、索引页

 

修改public_html/index.php中相关设置

 

1. 设置时区

date_default_timezone_set('Asia/Shanghai');

 

2. 错误报告

ERROR REPORTING

error_reporting(E_ALL| E_STRICT);

 

 

(二)、数据库

1. 环境设置

在用户配置目录(config)下新建两个文件夹:development和production

(1) 拷贝database.php

复制到两个文件夹下,并删除原database.php。

(2) 设置database

   设置”hostname”, “username”, “password”, “database”各值

   I. development

       $db['default']['pconnect'] =TRUE;

       更改为 FALSE

      

       $db['default']['stricton'] =FALSE;

       更改为 TRUE

  

 

 

  II. production

       除了$db['default']['autoinit'] =TRUE;

之外$db['default'][XXX]都设为 FALSE

 

 

(三)、项目配置

1. 配置文件

在config目录新建,项目名_config.php文件(testCI3_config.php)

    $config['site_name'] ='My test site';

 

2. 加载它

    在autoload.php加载它

$autoload['config'] = array('testCI3_config');

 

 

(四)、http访问

    在工作目录(public_html)增加一个访问规则文件(.htaccess)。

内容如下:

   <IfModule mod_rewrite.c>

 

    Options +FollowSymLinks

    RewriteEngine on

 

    # Send request via index.php

    RewriteCond %{REQUEST_FILENAME}!-f

    RewriteCond %{REQUEST_FILENAME}!-d

    RewriteRule ^(.*)$ index.php/$1[L]

 

</IfModule>

 

 

(五)、安全性

 

    我们在config.php中更改默认设置,以使CI支持安全特性。

 

1. 加密明文

    为了使密码不是明文,我们使用加密后的伪密码,这样会提高安全。

SHA512

 

文本字符串=明文密码+加密key。

 

 

$config['encryption_key'] = 'gh9K*fCsZa2@hBc&hjasLKVfVBNa*%f';

 

     

点击“计算”按钮,最下面的红色框中就是我们要的。

 (hashcalc slavasoft 下载)

 

2. Session

红色字体为更改的内容。

$config['sess_cookie_name']         ='cisession';

$config['sess_expiration']              =7200;

$config['sess_expire_on_close']     =TRUE;

$config['sess_encrypt_cookie']      =TRUE;

$config['sess_use_database']   =TRUE;

$config['sess_table_name']            ='ci_sessions';

$config['sess_match_ip']        =FALSE;

$config['sess_match_useragent']    =TRUE;

$config['sess_time_to_update']      =300;

 

 

数据表

详见ci_sessions

 

 

运行:

 

 

 

原创粉丝点击