1

I am sorry. Weak in english. Neglect Grammatical Errors. As i searched, i got to knew that session is being handled by controller. I'm not getting in which part i've to use session. How to bring data from model to controller to declare it session based values.

Controller

public function __construct()
    {
            parent::__construct();
            $this->load->model('news_model');
    $this->load->library('session');

    $this->load->helper('form');
    $this->load->library('form_validation');

    }
public function check_login()
    {
        $this->form_validation->set_rules('EmpID', 'Employee ID', 'required');
        $this->form_validation->set_rules('EmpPassword', 'Employee Password', 'required');

        if ($this->form_validation->run() === FALSE)
        {
        $this->load->view('templates/header');
        $this->load->view('welcome_message');
        $this->load->view('templates/footer');
        }
        else
        {
        $loginCredentials=$this->news_model->login_credentials();
        if($loginCredentials==='Member')
        {   
            redirect('/welcome/member_CAttachments'); //redirecting to member folder
        }

        }
}

Model

public function login_credentials()
    {
        $empID=$this->input->post('EmpID');

        $this->db->where('EmployeeID',$this->input->post('EmpID'));
        $this->db->where('Password',md5($this->input->post('EmpPassword')));
        $query=$this->db->get('member');

        if($query->num_rows()==1)
        {
            $this->db->where('EmployeeID=', $empID);
            $queryMemberType = $this->db->get('member');
            foreach ($queryMemberType->result() as $row)
            {
                $MemberType=$row->MemberType;
            }
            if($MemberType=='Admin')
            {
                return 'Admin';
            }
        }
        else
        {
            return false;
        }
    }
1
  • what i mean to say. That, OK. I can store email/employee Number using POST in session. But, What about that auto-incremented employee Id, which is in MODEL. Please help me. I'm new to it. Commented Aug 24, 2015 at 9:19

2 Answers 2

2

Once you get the data from model you just need to add that data to session object like this : $this->load->library('session'); $this->session->set_userdata('some_name', 'some_value');

And If you want to see session added data. you can use : $this->session->userdata('come_name ');

Sign up to request clarification or add additional context in comments.

Comments

1

in model if your condition if($query->num_rows()==1) { .... } is true then you need to set login employee data in session then you can access login employee information anywhere you can access in controller and also in view ...so please set session...it will work..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.