Why this code is ok
$this->sch_teacher_id = $this->ion_auth->user_by_username("vika")->row()->id;
But this doesn't work?
$this->sch_teacher_id = $this->ion_auth->user_by_username($this->uri->segment(3))->row()->id;
My url is domain:8888/admin_schedule/teacher/vika
route.php contains
$route['admin_schedule/teacher/(:any)'] = "admin_schedule/index/$1";
I use code lines in function __construct(), and the result of it use in another controller function, because 3 functions use this result. If I move this code in one of this functions and use $this->uri->segment(3) then I get not 'vika's lessons, but my own lessons, so
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;
}
works good. But $this->uri->segment(3) if use it as parameter in user_by_username function, doesn't work!
page generated next way: controller admin_schedule have function index which render view index.php. And in that view I use javascript, that call another function from admin_schedule controller = get_schedule_db_recurring_events_on_daysweek such way:
...
{
url: '/admin_schedule/get_schedule_db_recurring_events_on_daysweek/',//"<?echo $data_path?>",
backgroundColor: 'red',
}
and in controller
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);
}
}
Please, help understand this problem.