當前位置:首頁 » 編程語言 » php的ci框架

php的ci框架

發布時間: 2022-06-11 17:33:34

❶ 如何讓nginx支持php的ci框架

1、修改ci框架的配置文件
修改$config['uri_protocol']值
改為:
$config['uri_protocol'] = 'PATH_INFO';

2、修改nginx配置文件,在SERVER段中添加如下代碼:
location /index.php{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_param SCRIPT_FILENAME /home/wwwroot/index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fcgi.conf;
}

如果有多個應用,如:後台應用,可以多加一段以上代碼,並修改相應入口文件:
location /admin.php{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_param SCRIPT_FILENAME /home/wwwroot/admin.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fcgi.conf;
}

❷ PHP CI框架修改數據的方法

CI框架下的PHP增刪改查總結:
controllers下的 cquery.php文件
[php] view plain
<?php

class CQuery extends Controller {

//構造函數
function CQuery() {
parent::Controller();
// $this->load->database();

}

function index() {
//調用model 其中train為外層文件夾 MQuery為model名稱 queryList為重命名
$this->load->model('train/MQuery','queryList');
//獲得返回的結果集 這里確定調用model中的哪個方法
$result = $this->queryList->queryList();
//將結果集賦給res
$this->smarty->assign('res',$result);
//跳轉到顯示頁面
$this->smarty->view('train/vquery.tpl');
}

//進入新增頁面
function addPage() {
$this->smarty->view('train/addPage.tpl');
}

//新增
function add() {
//獲得前台數據
//用戶名
$memberName = $this->input->post('memberName');
//密碼
$password = $this->input->post('password');
//真實姓名
$userRealName = $this->input->post('userRealName');
//性別
$sex = $this->input->post('sex');
//出生日期
$bornDay = $this->input->post('bornDay');
//e_mail
$eMail = $this->input->post('eMail');
//密碼問題
$question = $this->input->post('question');
//密碼答案
$answer = $this->input->post('answer');
//調用model
$this->load->model('train/MQuery','addRecord');
//向model中的addRecord傳值
$result = $this->addRecord->addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer);
//判斷返回的結果,如果返回true,則調用本頁的index方法,不要寫 $result == false 因為返回的值未必是false 也有可能是""
if ($result) {
$this->index();
} else {
echo "add failed.";
}
}
//刪除
function deletePage() {
//獲得ID
$deleteID = $this->uri->segment(4);
//調用model
$this->load->model('train/MQuery','delRecord');
//將值傳入到model的delRecord方法中
$result = $this->delRecord->delRecord($deleteID);
//判斷返回值
if ($result) {
$this->index();
} else {
echo "delect failed.";
}
}
//修改先查詢
function changePage() {
$changeID = $this->uri->segment(4);
$this->load->model('train/MQuery','changeRecord');
$result = $this->changeRecord->changeRecord($changeID);
//將結果集賦給res
$this->smarty->assign('res',$result);

//跳轉到顯示頁面
$this->smarty->view('train/changePage.tpl');
}
//修改
function change() {
//獲得前台數據
//ID
$ID = $this->input->post('id');
//用戶名
$memberName = $this->input->post('memberName');
//密碼
$password = $this->input->post('password');
//真實姓名
$userRealName = $this->input->post('userRealName');
//性別
$sex = $this->input->post('sex');
//出生日期
$bornDay = $this->input->post('bornDay');
//e_mail
$eMail = $this->input->post('eMail');
//密碼問題
$question = $this->input->post('question');
//密碼答案
$answer = $this->input->post('answer');
//調用model
$this->load->model('train/MQuery','change');
//向model中的change傳值
$result = $this->change->change($ID,$memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer);
//判斷返回的結果,如果返回true,則調用本頁的index方法,不要寫 $result == false 因為返回的值未必是false 也有可能是""
if ($result) {
$this->index();
} else {
echo "change failed.";
}
}
}
models中的 mquery.php 文件
[php] view plain
<?php

class MQuery extends Model {
//構造函數
function MQuery() {
parent::Model();
//連接資料庫
$this->load->database();
}

//查詢列表
function queryList() {
//防止select出的數據存在亂碼問題
//mysql_query("SET NAMES GBK");
//SQL語句
$sql = "SELECT ID,member_name,sex,e_mail FROM user_info_t";
//執行SQL
$rs = $this->db->query($sql);
//將查詢結果放入到結果集中
$result = $rs->result();
//關閉資料庫
$this->db->close();
//將結果集返回
return $result;
}

//新增
function addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer) {
//防止select出的數據存在亂碼問題
//mysql_query("SET NAMES GBK");
//SQL語句
$sql = "INSERT INTO user_info_t (member_name,password,user_real_name,sex,born_day,e_mail,question,answer) " .
"VALUES ('$memberName','$password','$userRealName','$sex','$bornDay','$eMail','$question','$answer')";
//執行SQL
$result = $this->db->query($sql);
//關閉資料庫
$this->db->close();
//返回值
return $result;
}

//刪除
function delRecord($deleteID) {
//防止select出的數據存在亂碼問題
//mysql_query("SET NAMES GBK");
$sql = "DELETE FROM user_info_t WHERE ID = $deleteID";
$result = $this->db->query($sql);
$this->db->close();
return $result;
}

//修改前查詢
function changeRecord($changeID) {
//防止select出的數據存在亂碼問題
//mysql_query("SET NAMES GBK");
$sql = "SELECT ID,member_name,password,user_real_name,sex,born_day,e_mail,question,answer FROM user_info_t WHERE ID = $changeID";
//執行SQL
$rs = $this->db->query($sql);
$result = $rs->row();//$result = $rs[0]
//關閉資料庫
$this->db->close();
//將結果集返回
return $result;
}

//修改
function change($ID,$memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer) {
//防止select出的數據存在亂碼問題
//mysql_query("SET NAMES GBK");
//SQL語句
$sql = "update user_info_t set member_name = '$memberName',password = '$password', user_real_name = '$userRealName'," .
"sex = '$sex',born_day = '$bornDay',e_mail = '$eMail',question = '$question',answer = '$answer'" .
"where ID = $ID";
//執行SQL
$result = $this->db->query($sql);
//關閉資料庫
$this->db->close();
//返回值
return $result;
}
}

views 下的 addPage.tpl文件

[php] view plain
<html>
<head>
</head>
<body><form action="{{site_url url='train/cquery/add'}}" method="post">
<table border='1'>

<tr>
<td>用戶名</td>
<td><input type="text" class="text" name="memberName" id="memberName"/></td>
</tr>
<tr>
<td>密碼</td>
<td><input type="text" class="text" name="password" id="password"/></td>
</tr>
<tr>
<td>真實姓名</td>
<td><input type="text" class="text" name="userRealName" id="userRealName"/></td>
</tr>
<tr>
<td>性別</td>
<td><input type="text" class="text" name="sex" id="sex"/></td>
</tr>
<tr>
<td>出生日期</td>
<td><input type="text" class="text" name="bornDay" id="bornDay"/></td>
</tr>
<tr>
<td>e_mail</td>
<td><input type="text" class="text" name="eMail" id="eMail"/></td>
</tr>
<tr>
<td>密碼問題</td>
<td><input type="text" class="text" name="question" id="question"/></td>
</tr>
<tr>
<td>密碼答案</td>
<td><input type="text" class="text" name="answer" id="answer"/></td>
</tr>

</table>
<table>
<tr>
<td><input type="submit" class="button" name="OK" value="提交" />
</td>
</tr>
</table></form>
</body>
</html>

❸ 有人熟悉php的ci框架么

你好,我有參與過CI框架的項目開發工作,你是想問如何學習CI框架和CI框架的流行程度吧。
學習CI框架,我建議你可以使用視頻學習,也可以直接觀看CI框架的手冊進行學習。這樣效率其實會更高。對於CI框架的流行程度,其實不管在國內還是國外,CI還是屬於比較流行的PHP框架。就業前景也不錯。

❹ php的CI框架如何實現非同步調用

在你自定義的類庫中初始化CodeIgniter資源

要你自定義的類庫中訪問CodeIgniter的原始資源,你必須使用 get_instance() 函數.這個函數返回一個CodeIgniter super object.

一般來說在你的控制器函數中你可以通過 $this 調用任何可用的CodeIgniter函數:
$this->load->helper('url');
$this->load->library('session');
$this->config->item('base_url');
//etc.
$this, 只直接作用在你自己的控制器,模型和視圖中.當你在自定義類中想使用CodeIgniter原始類時,你可以這樣做:

首先,定義CodeIgniter對象賦給一個變數:
$CI =& get_instance();
一旦定義某個對象為一個變數,你就可以使用那個變數名 取代 $this:
$CI =& get_instance();

$CI->load->helper('url');
$CI->load->library('session');
$CI->config->item('base_url');
//etc.
注意: 你將注意到get_instance()這個函數通過被引用的方式被傳遞:

$CI =& get_instance();

這十分重要. 通過引用的方式賦給變數將使用原始的 CodeIgniter 對象,而不是創建一個副本。

//------------------------------------------------------------------------------------------------//
我想這也許是你需要的.$CI =& get_instance();之後再用$CI->load->library('session');等方法載入你需要的

❺ 用php的CI框架怎麼寫登錄和注冊

第一步:login.php

//登陸方法
public function login(){
//如果用戶名和密碼為空,則返回登陸頁面
if(empty($_POST['username']) || empty($_POST['password'])){
$data['verifycode'] = rand(1000,9999);//生成一個四位數字的驗證碼
//將驗證碼放入session中,注意:參數是數組的格式
$this->session->set_userdata($data);
//注意:CI框架默認模板引擎解析的模板文件中變數不需要$符號
//$this->parser->parse("admin/login",$data);
//smarty模板變數賦值
$this->tp->assign("verifycode",$data['verifycode']);
//ci框架在模板文件中使用原生態的PHP語法輸出數據
//$this->load->view('login',$data);//登陸頁面,注意:參數2需要以數組的形式出現
//顯示smarty模板引擎設定的模板文件
$this->tp->display("admin/login.php");
}else{
$username = isset($_POST['username'])&&!empty($_POST['username'])?trim($_POST['username']):'';//用戶名
$password = isset($_POST['password'])&&!empty($_POST['password'])?trim($_POST['password']):'';//密碼
$verifycode = isset($_POST['verifycode'])&&!empty($_POST['verifycode'])?trim($_POST['verifycode']):'';//驗證碼

//做驗證碼的校驗
if($verifycode == $this->session->userdata('verifycode')){
//根據用戶名及密碼獲取用戶信息,注意:參數2是加密的密碼
$user_info=$this->user_model->check_user_login($username,md5($password));
if($user_info['user_id'] > 0){
//將用戶id、username、password放入cookie中
//第一種設置cookie的方式:採用php原生態的方法設置的cookie的值
//setcookie("user_id",$user_info['user_id'],86500);
//setcookie("username",$user_info['username'],86500);
//setcookie("password",$user_info['password'],86500);
//echo $_COOKIE['username'];

//第二種設置cookie的方式:通過CI框架的input類庫
$this->input->set_cookie("username",$user_info['username'],3600);
$this->input->set_cookie("password",$user_info['password'],3600);
$this->input->set_cookie("user_id",$user_info['user_id'],3600);
//echo $this->input->cookie("password");//適用於控制器
//echo $this->input->cookie("username");//適用於控制器
//echo $_COOKIE['username'];//在模型類中可以通過這種方式獲取cookie值
//echo $_COOKIE['password'];//在模型類中可以通過這種方式獲取cookie值

//第三種設置cookie的方式:通過CI框架的cookie_helper.php函數庫文件
//這種方式不是很靈驗,建議大家採取第二種方式即可
//set_cookie("username",$user_info['username'],3600);
//echo get_cookie("username");

//session登陸時使用:將用戶名和用戶id存入session中
//$data['username']=$user_info['username'];
//$data['user_id']=$user_info['user_id'];
//$this->session->set_userdata($data);

//跳轉到指定頁面
//注意:site_url()與base_url()的區別,前者帶index.php,後者不帶index.php
header("location:".site_url("index/index"));
}
}else{
//跳轉到登陸頁面
header("location:".site_url("common/login"));
}
}
}
}

第二步:User_model.php

//cookie登陸:檢測用戶是否登陸,如果cookie值失效,則返回false,如果cookie值未失效,則根據cookie中的用戶名和密碼從資料庫中獲取用戶信息,如果能獲取到用戶信息,則返回查詢到的用戶信息,如果沒有查詢到用戶信息,則返回0
public function is_login(){
//獲取cookie中的值
if(empty($_COOKIE['username']) || empty($_COOKIE['password'])){
$user_info = false;
}else{
$user_info=$this->check_user_login($_COOKIE['username'],$_COOKIE['password']);
}
return $user_info;
}

//根據用戶名及加密密碼從資料庫中獲取用戶信息,如果能獲取到,則返回獲取到的用戶信息,否則返回false,注意:密碼為加密密碼
public function check_user_login($username,$password){
//這里大家要注意:$password為md5加密後的密碼
//$this->db->query("select * from ");
//快捷查詢類的使用:能為我們提供快速獲取數據的方法
//此數組為查詢條件
//注意:關聯數組
$arr=array(
'username'=>$username,//用戶名
'password'=>$password,//加密密碼
'status'=>1 //賬戶為開啟狀態
);
//在database.php文件中已經設置了數據表的前綴,所以此時數據表無需帶前綴
$query = $this->db->get_where("users",$arr);
//返回二維數組
//$data=$query->result_array();
//返回一維數組
$user_info=$query->row_array();
if(!empty($user_info)){
return $user_info;
}else{
return false;
}
}

第三步:其它控制器:

public function __construct(){

//調用父類的構造函數
parent::__construct();
$this->load->library('tp'); //smarty模板解析類
$this->load->helper('url'); //url函數庫文件
$this->load->model("user_model");//User_model模型類實例化對象
$this->cur_user=$this->user_model->is_login();
if($this->cur_user === false){
header("location:".site_url("common/login"));
}else{
//如果已經登陸,則重新設置cookie的有效期
$this->input->set_cookie("username",$this->cur_user['username'],3600);
$this->input->set_cookie("password",$this->cur_user['password'],3600);
$this->input->set_cookie("user_id",$this->cur_user['user_id'],3600);
}

$this->load->library('pagination');//分頁類庫
$this->load->model("role_model");//member_model模型類
$this->load->model("operation_model");//引用operation_model模型
$this->load->model("object_model");//引用object_model模型
$this->load->model("permission_model");//引用permission_model模型
}

❻ phpCI框架 如何去掉默認index.php

下面是去掉index.php的操作
PHP CodeIgniter(CI)去掉 index.php - Langjun - 博客園
設置訪問的默認路徑是在
文件下,找到
$route['default_controller'] = "index"; 默認的為welcome 改為你的訪問index.php之後的參數
我的訪問首頁

遇到類似的問題,你可以去後盾人平台看看的哦,裡面的東西不錯應該能幫你解決一些不明白的問題(❁´◡`❁)*

❼ php的ci框架中的分頁類應該怎樣使用

你需要自己在查詢裡面加上 offset 和 limit 限制

public function article_list($limit,$offset)
{
$query = $this->db->get('article',$limit,$offset);
$result = $query->result_array();
$data['articles'] = $result;
$this->load->view('news.php',$data);
}

❽ php的CI框架,如何使用session

裡面有兩種session的使用方法:
1是php的原始的session使用方法,這個很簡單,$_SESSION['name']="name",然後在需要的地方顯示:echo $_SESSION['name'];
2是codeigniter這個框架的一個方法:
下面就詳細講解如何使用這個有點點復雜的方法:
首先,在\ci\application\config下面的config.php文件中找到:$config['encryption_key'] = '';這個裡面隨便填什麼值都可以,但是不能為空。一般是英文啊,不要鑽牛角尖。
接著在\ci\application\config下面的auto.php文件中找到:$autoload['libraries'] = array('');裡面要填寫:$autoload['libraries'] = array('session');或者在適當的地方如control文件夾裡面的相應文件中(一般是在構造方法中)寫:$this->load->library('session');這樣也行。
現在環境配置好了,現在就是寫代碼了:
在需要放入session的地方寫:
$this->session->set_userdata('name','yang');
這樣session裡面就有了值了。
顯示值:
echo $this->session->userdata('name');
如果是array,則:
$newdata = array(
'username' => 'johndoe',
'email' => '[email protected]',
'logged_in' => TRUE
);
$this->session->set_userdata($newdata);
以下是轉載的別人的詳細的有點廢話的相關知識:
Sessions會在每個頁面載入後開始運行,所以session類必須首先被初始化。

1、您可以在控制器中初始化,也可以在系統中自動載入(譯者註:在autoload.php設定)$autoload['libraries'] = array('session');

2、要在您的控制器構造函數中初始化session類,您可以使用 $this->load->library 函數:$this->load->library('session');一旦被載入, session就可以這樣使用: $this->session。
session類的絕大部分都會在後台運行,所以初始化session時,它session數據會被自動讀取、創建和更新。

Sessions 是怎樣工作的?
需要知道的非常重要的一點就是,session類一旦被初始化,它就會自動運行。對於後面的事情,您可以完全不作理會。正如您將會在下面看到的一樣,您可以正常使用session來工作,甚至還可以添加自己的session數據,而在這一切的過程中,讀、寫和更新的操作都是自動完成的。

當頁面載入後,session類就會檢查用戶的cookie中是否存在有效的session數據。如果session數據不存在(或者已經過期),那麼就會創建一個新的session並把他保存在cookie中。如果session數據存在,那麼他的信息就會被更新,同時cookie也會被同時更新。每次更新都會重新生成session_id的值。

默認情況下, Session Cookie 每隔 5 分鍾才會更新一次,這樣會減少對處理器的負荷。如果你重復的裝載頁面, 你會發現"上次活動"的時間在五分鍾,或多餘五分鍾的時候才會變化,也就是 cookie上次被寫入的時間。 這個時間可以通過設置 application/config/config.php 文件里的 $config['sess_time_to_update'] 行來改變。

❾ 請問php中ci框架這是怎麼回事

兩種原因:
1.php代碼沒有運行;

2.代碼需要轉換一下,要麼是編碼不對,要麼是都轉換成了實體字元。

❿ Php的ci框架怎麼做後台管理系統一些按鈕怎麼寫出來的!

ci框架只提供一系列後端代碼的擴展以及管理,你想要寫個後台管理系統需要自己寫,不像drupal可以直接生成代碼。

熱點內容
電腦如何區域網共享文件夾 發布:2024-05-19 01:25:01 瀏覽:67
手機存儲越大性能越好嗎 發布:2024-05-19 01:14:28 瀏覽:176
我的世界hyp伺服器怎麼玩 發布:2024-05-19 00:51:25 瀏覽:801
手機如何解壓百度雲文件 發布:2024-05-19 00:32:24 瀏覽:905
centos使用python 發布:2024-05-18 23:39:48 瀏覽:868
幻影天龍腳本 發布:2024-05-18 23:38:17 瀏覽:712
編程的py 發布:2024-05-18 23:36:22 瀏覽:75
安卓系統怎麼改序列號 發布:2024-05-18 23:28:16 瀏覽:783
c語言中實數 發布:2024-05-18 23:21:03 瀏覽:895
伺服器搭建題目 發布:2024-05-18 23:01:29 瀏覽:28