Welcome Guest, Not a member yet? Register   Sign In
Avoiding deep-nesting of if/else statements in controllers?
#1

[eluser]sorenchr[/eluser]
You know the deal.. halfway through working on your controller that handles logins your code looks something like this:

Code:
if($this->form_validation->run() == TRUE)
{
    // Check if user validates using email/password combination
    $this->load->model('accounts');
    if(is_array($user_array = $this->accounts->get_user_array($this->input->post('login-email'))))
    {
        // Does the password entered match the password in the db?
        if(crypt($this->input->post('login-password'), $user_array['password']) == $user_array['password'])
        {
            // Correct password
        }

        else
        {
        // Incorrect password
        }
    }

    else
    {
        // no user exists by that email
    }
}

else
{
    // form did not validate
}

Is there a way to avoid this? Possibly by 'stopping' the controller if a single statement is true? Like:

Code:
if(statement)
{
  // Stop controller here
}


Messages In This Thread
Avoiding deep-nesting of if/else statements in controllers? - by El Forum - 07-09-2010, 05:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB