【发布时间】:2015-02-09 11:22:11
【问题描述】:
我正在开发一个 CodeIgniter 项目。 我想将一个 uri 段从控制器传递到我自己的库。 我做不到..我用 session 试过了,但它不起作用。请帮助我..
这是我的控制器,
<?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();
}
}
在库中,我尝试获取会话数据,但我将会话数据“id”设为 0 ... 当我使用 uri->segemnt(2) 时。它将获得正确的值,但 uri->segment(3) 不起作用...请帮助我
【问题讨论】:
-
echo $this->uri->segment(3);并检查它是否需要值,并检查控制器本身的回显会话值。
-
为什么不将 id 作为必需参数传递给函数?
标签: php codeigniter