php结合phpStudy实例来熟悉CI框架,用的软件是phpStorm+phpStudy
1、新建项目名字,我的是放在E盘,叫test,主要是包括application,system,index.php。我的控制器和视图不想放在application中,所以我新建了一个文件夹叫phpTest,将application目录里面的东西复制一份到phpTest文件中,然后需要在index.php中改变一下指向路径。

2、在phpStorm中运行项目,你需要做配置。
(1)在phpStudy中配置:
a、打开配置文件-》php-ini文件,找到xdebug

b、打开配置文件-》vhost-conf文件,进行配置

c、打开hosts文件,

(2)在phpstorm中进行配置
a、file-》settings->出现的弹框如下:
a、

b、




注意:我在运行的时候出现了一个问题:
Disallowed Key Characters错误提示
解决办法:
决 CodeIgniter 框架应用中,出现Disallowed Key Characters错误提示的方法。找到core文件夹下的Input文件,将下面的代码:
function _clean_input_keys($str)
{
if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
{
exit('Disallowed Key Characters.');
}
// Clean UTF-8 if supported
if (UTF8_ENABLED === TRUE)
{
$str = $this->uni->clean_string($str);
}
return $str;
}
修改为:
function _clean_input_keys($str)
{
$config = &get_config('config');
if ( ! preg_match("/^[".$config['permitted_uri_chars']."]+$/i", rawurlencode($str)))
{
exit('Disallowed Key Characters.');
}
// Clean UTF-8 if supported
if (UTF8_ENABLED === TRUE)
{
$str = $this->uni->clean_string($str);
}
return $str;
}
或者改为:
function _clean_input_keys($str)
{
if(preg_match("/^,_[a-z0-9:_\/-]+$/",$str)){
$str = preg_replace("/,_/","",$str);
}
if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
{
exit('Disallowed Key Characters.'.$str);
}
return $str;
}
3、在项目根目录的index.php中修改$system_path的路径,改为你创建的phpTest目录的名字。

4、新建一个示例,步骤如下:

注意:前端的css或者图片或者js,可以在根目录下存放,如上图的style目录。
Controllers目录下的test中的test_1.php,代码如下:
<?php
/**
* Created by PhpStorm.
* User: lqf
* Date: 2016/6/21
* Time: 16:46
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class Test_1 extends CI_Controller{//继承CI框架
function __construct(){//方法体,通常用来对成员属性进行初始化赋值
parent:: __construct();//调用父类的构造器
header("Content-type: text/html; charset=utf-8");
}
public function one(){//方法名
$this->load->view('test/test1');//加载视图
}
}
views目录下的test中的test1.php,代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<title>新闻栏目类型管理</title>
<link rel="stylesheet" href="/style/css/base.css" /><!--引入css文件路径这样写就行,从根目录找-->
<style type="text/css">
html,body{
background: #3399FF;
}
.add-box{
width: 200px;
position: absolute;
top: 50%;
height: 100px;
left: 50%;
margin-left: -100px;
margin-top: -50px;
}
#menuName{
width: 180px;
font-size: 18px;
color: #333333;
padding: 12px 20px;
border: none;
}
#ok-btn{
margin: 20px;
width: 100px;
height: 30px;
line-height: 30px;
font-size: 18px;
background: #FFFFFF;
color: #000000;
text-align: center;
border: none;
}
</style>
</head>
<body>
<!--<div class="backbox" onclick="history.go(-1)">
<img src="/style/img/back-btn.png" />
</div>-->
<div class="add-box">
<form action="./addType" method="post">
<input type="text" name="menuName" id="menuName" placeholder="请输入栏目名称"/>
<input type="submit" value="确定" id="ok-btn"/>
</form>
</div>
</body>
</html>
写好后:运行如下图:


浙公网安备 33010602011771号