在会话中保存uri段以将其发送回模型。 笨

I just don't want to have such a duplicate function in a model, however I need to use that function again with a little change in it.

The little change is:

In the $first->get->model, I need to pass a segment url such as 'where id = $this->uri->segment(3)',

However, in the $second->get->model, I don't have that segment url anymore but have already save it to a session.

For example: (Please have a look to this code)

function get_regidsterLogin($limit, $offset) //There is no problem with $limit and $offset
    {

        $this->load->database();

        $this->db->select(' ds.userid,
                            ds.register_time,
                            gl.logintime
                          '); 

        $this->db->from('data_stats ds');

        $this->db->join('game_login gl', 'gl.data_id = ds.dataid', 'inner');

        //Here is what I want to change with session that I will send from view or maybe controller
        $this->db->where('DATE(register_time)', $this->uri->segment(3));

        $this->db->limit($limit, $offset);

        $query = $this->db->get(); 

          if($query->num_rows() > 0)
            {
                foreach ($query->result() as $row)
                {
                    $data[] = $row;
                }
                    return $data; 
            }

    }       

Is there a simple smart way to do this?

Thanks in advance.

You could either add a third argument and specify it every time or you could just test the segment in your function and if it is not there then use the session data:

 if($this->uri->segment(3) === TRUE{
     $uri = $this->uri->segment(3);
} else {
     $uri = $this->session->userdata('user_id') // or whatever your session variable is
}

So a full example would look something like:

(I shortened up the above statement to a ternary expression for the example)

function get_regidsterLogin($limit, $offset) //There is no problem with $limit and $offset
{
    $uri = ($this->uri-sement(3) == true ? $this->uri-sement(3) : $this->session->userdata(id));
    $this->load->database();

    $this->db->select(' ds.userid,
                        ds.register_time,
                        gl.logintime
                      '); 

    $this->db->from('data_stats ds');

    $this->db->join('game_login gl', 'gl.data_id = ds.dataid', 'inner');

    //Here is what I want to change with session that I will send from view or maybe controller
    $this->db->where('DATE(register_time)', $uri);

    $this->db->limit($limit, $offset);

    $query = $this->db->get(); 

      if($query->num_rows() > 0)
        {
            foreach ($query->result() as $row)
            {
                $data[] = $row;
            }
                return $data; 
        }

}