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>

寫好后:運行如下圖:

 

 
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM