为什么这段代码没问题
$this->sch_teacher_id = $this->ion_auth->user_by_username("vika")->row()->id;
但这不起作用?
$this->sch_teacher_id = $this->ion_auth->user_by_username($this->uri->segment(3))->row()->id;
我的网址是 domain:8888/admin_schedule/teacher/vika
route.php 包含
$route['admin_schedule/teacher/(:any)'] = "admin_schedule/index/$1";
我在函数 __construct()中使用代码行,它的结果在另一个控制器函数中使用,因为 3 个函数使用这个结果。如果我将此代码移动到其中一个函数中并使用$this->uri->segment(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 的函数 index。在那个视图中,我使用 javascript,从 admin_schedule controller = 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);
}
}
请帮助理解这个问题。