title: Codeigniter can't use this->uri->segment(3) as value in function
body: <p>Why this code is ok</p>
  
  <pre><code>$this-&gt;sch_teacher_id = $this-&gt;ion_auth-&gt;user_by_username("vika")-&gt;row()-&gt;id;
  </code></pre>
  
  <p>But this doesn't work?</p>
  
  <pre><code>$this-&gt;sch_teacher_id = $this-&gt;ion_auth-&gt;user_by_username($this-&gt;uri-&gt;segment(3))-&gt;row()-&gt;id;
  </code></pre>
  
  <p>My url is domain:8888/admin_schedule/teacher/vika</p>
  
  <p>route.php contains</p>
  
  <pre><code>$route['admin_schedule/teacher/(:any)'] = "admin_schedule/index/$1";
  </code></pre>
  
  <p>I use code lines in <strong>function __construct()</strong>, 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 <strong>$this->uri->segment(3)</strong> then I get not 'vika's lessons, but <em>my own lessons</em>, so </p>
  
  <pre><code>public function user_by_username($username = FALSE)
      {
          $this-&gt;trigger_events('user');
  
          //if no id was passed use the current users id
          $username || $username = $this-&gt;session-&gt;userdata('username');
  
          $this-&gt;limit(1);
          $this-&gt;where($this-&gt;tables['users'].'.username', $username);
  
          $this-&gt;users();
  
          return $this;
      } 
  </code></pre>
  
  <p>works good. But $this->uri->segment(3) if use it as parameter in user_by_username function, doesn't work!</p>
  
  <p>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:</p>
  
  <pre><code>...
  {
                  url: '/admin_schedule/get_schedule_db_recurring_events_on_daysweek/',//"&lt;?echo $data_path?&gt;",
                  backgroundColor: 'red',
              }
  </code></pre>
  
  <p>and in controller</p>
  
  <pre><code>function get_schedule_db_recurring_events_on_daysweek()
      {   
          $start = date('Y-m-d H:i', $this-&gt;input-&gt;get('start')); 
          $end = date('Y-m-d H:i', $this-&gt;input-&gt;get('end')); 
          $sch_teacher_id = $this-&gt;uri-&gt;segment(3); // &lt;--- this doesn't work, but $sch_teacher_id = 111 works perfectly
          $result=$this-&gt;Schedule_model-&gt;get_schedule_recurring_events_on_daysweek($start, $end, $sch_teacher_id);
          $count=count($result);      
          if($count&gt;0){
                  echo json_encode($result);
          }
      }
  </code></pre>
  
  <p>Please, help understand this problem.</p>