Welcome Guest, Not a member yet? Register   Sign In
challenge calling function within class
#1

[eluser]dwlamb[/eluser]
Ok, CI and OOP newbie question.

I've integrated a log-in for an application and am having a challenge with the function to call if a user is not logged-in.

Below is the code for setting-up and processing the log-in form:
Code:
function index () {
    $this->load->helper(array('form', 'url'));
    $this->load->library('Form_validation');
    $this->form_validation->set_rules('e-mail', 'E-mail address', 'required');
    $this->form_validation->set_rules('pwd', 'password', 'required');
    $data['form_open'] = form_open('welcome/index');
    if ($this->form_validation->run() == FALSE) {
        $this->load->view('welcome_login', $data);
    }
    else {
        $this->form_validation->set_rules('pwd', 'Password', 'trim|required|matches[pwd2]|md5|xss_clean');
        $this->form_validation->set_rules('e-mail', 'Email', 'trim|required|valid_email|xss_clean');
        $this->simpleloginsecure->login($this->input->post('e-mail'), $this->input->post('pwd'));
        $this->check_login();            
    }
}

This is the function check_login:

Code:
function check_login() {
    if($this->session->userdata('logged_in')) {
        $this->recipe();
    } else {
        $this->index();
    }
}

If check_login() is FALSE, the browser does not load the form to start the process over again. It simply hangs on loading. The same happens if I do this:

Code:
function index () {
    $this->load->helper(array('form', 'url'));
    $this->load->library('Form_validation');
    $this->form_validation->set_rules('e-mail', 'E-mail address', 'required');
    $this->form_validation->set_rules('pwd', 'password', 'required');
    $data['form_open'] = form_open('welcome/index');
    if ($this->form_validation->run() == FALSE) {
        $this->load->view('welcome_login', $data);
    }
    else {
        $this->form_validation->set_rules('pwd', 'Password', 'trim|required|matches[pwd2]|md5|xss_clean');
        $this->form_validation->set_rules('e-mail', 'Email', 'trim|required|valid_email|xss_clean');
        $this->simpleloginsecure->login($this->input->post('e-mail'), $this->input->post('pwd'));
        if($this->session->userdata('logged_in')) {
            $this->recipe();
        } else {
            $this->index();
        }
    }
}

What is the best way to call a function of a class from another function in that same class?

Thanks in advance.




Theme © iAndrew 2016 - Forum software by © MyBB