我正在研究CodeIgniter項目.. 我想將uri片段從控制器傳遞到我自己的庫。 我不能能夠做到這一點。我嘗試過使用會話,但它不會work.please幫助我..將uri片段傳遞到codeIgniter中的庫
這是我的控制器,
<?php
class insertdata extends CI_Controller{
function __construct(){
parent::__construct();
}
//#############################################################################
function updateprop(){
$this->load->library('DataEntryForms_update');
//get the uri segment
$id = $this->uri->segment(3);
//setting the session data
$this->session->set_userdata('id',$id);
$params [] = $this->uri->segment(3);
$form_name = $this->input->post('function_name');
switch ($function_name){
case 1:
$this->dataentryforms_update->function1();
break;
case 2:
$this->dataentryforms_update->function2();
break;
}
}
}
這是我的圖書館.. 。
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class DataEntryForms_update{
protected $CI;
#######################################################
//gets the CI instance
function __construct(){
$this->CI =& get_instance();
}
#############################################################
function function1($params){
$this->params = $params;
print_r ($this->params);
$project_id = $this->CI->session->userdata('id');
echo $project_id;
die();
}
}
在圖書館我試圖獲取會話數據,但我得到的會話數據「身份證」爲0 ... 當我使用URI-> segemnt(2)。它會得到正確的值,但是uri-> segment(3)不起作用...請幫助我
echo $ this-> uri-> segment(3);並檢查是否需要值,並檢查控制器本身的回聲會話值。 – Vamsi 2012-08-06 06:28:04
爲什麼你不把id作爲必需的參數傳遞給你的函數? – rrrhys 2012-08-06 06:32:30