使用这个 - > URI->段(3)价值?笨不能在功能
$this->sch_teacher_id = $this->ion_auth->user_by_username($this->uri->segment(3))->row()->id;
我的网址域名:8888/admin_schedule /教师/ VIKA
route.php包含
$route['admin_schedule/teacher/(:any)'] = "admin_schedule/index/$1";
我使用的代码行功能__construct(),和结果它在另一个控制器功能中使用,因为3个功能使用此结果。如果我在这个功能中的一个移动这个代码,并使用$这个 - > URI->段(3)然后我得到不是“VIKA的教训,但我自己的经验教训,所以
public function user_by_username($username = FALSE)
{
$this->trigger_events('user');
//if no id was passed use the current users id
$username || $username = $this->session->userdata('username');
$this->limit(1);
$this->where($this->tables['users'].'.username', $username);
$this->users();
return $this;
}
做工不错。但是$ this-> uri-> segment(3)如果在user_by_username函数中使用它作为参数,则不起作用!
下一页生成的页面: 控制器admin_schedule具有渲染视图index.php的函数索引。 并在该视图中使用JavaScript,调用另一个函数从admin_schedule控制器= get_schedule_db_recurring_events_on_daysweek这样的方式:
...
{
url: '/admin_schedule/get_schedule_db_recurring_events_on_daysweek/',//"<?echo $data_path?>",
backgroundColor: 'red',
}
和控制器
function get_schedule_db_recurring_events_on_daysweek()
{
$start = date('Y-m-d H:i', $this->input->get('start'));
$end = date('Y-m-d H:i', $this->input->get('end'));
$sch_teacher_id = $this->uri->segment(3); // <--- this doesn't work, but $sch_teacher_id = 111 works perfectly
$result=$this->Schedule_model->get_schedule_recurring_events_on_daysweek($start, $end, $sch_teacher_id);
$count=count($result);
if($count>0){
echo json_encode($result);
}
}
请,有助于理解这个问题。
您是否尝试将其分配给一个变量并回显以查看发生了什么? – rcdmk
是的,当然是:$ username1 =“'”。$ this-> uri-> segment(3)。“'”; \t \t print_r($ username1);这张照片应该是'vika'。 – almix
如果是这样,您的最后一个问题已经得到解答。这给我们留下了主要问题。你有没有试图将这个值与一个变量而不是直接传递给该方法(看起来很奇怪,但在某些情况下会引起一些引用问题)。试试吧。 – rcdmk