Welcome Guest, Not a member yet? Register   Sign In
Avoiding nesting everything inside IF statements
#2

[eluser]kurucu[/eluser]
No, I use return like that to escape from the controller after displaying errors (e.g. when a specific index is not found, and showing a default is not valid). It hasn't bitten me yet.

I guess you'd have different things in place of $logged_in, if you want to test for a specific role etc?

However... While having code nested inside a bunch of IF statements doesn't look nice, that doesn't mean it is necessarily inelegant code! It might be perfect logic and very efficient, but the human programmer is allergic to it Smile

If have a bunch of
Code:
if( $this->user->can('delete_blog_entries') )
{
    //delete entry/show the form
} else {
    //invite them to log in
    //'inelegant', but will later allow me to (for example) cache the demand
    //so that I can act on it once they do log in
}

If the controller needn't offer complexity, I do exactly what you do
Code:
if(!$page = $this->pagemodel->get_page($id) ){ $this->standard_message('invalid_page'); return; }
// same for permissions
// ... other things to check, all returning with a message if failed

// then show act/show form/process form

So I'm potentially waiting for the same wall to creep up on me!


Messages In This Thread
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 08:46 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 09:06 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 09:26 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 09:34 AM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 01:00 PM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 04:26 PM
Avoiding nesting everything inside IF statements - by El Forum - 09-29-2009, 06:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB