Welcome Guest, Not a member yet? Register   Sign In
Repeating Code in Controller
#1

[eluser]Unknown[/eluser]
Hello all,

My problem is I'm finding that I'm repeating my code in the controllers and was wondering if there was a better way of handling it? In the below code I have index and settings_profile functions... within those I have several arrays that do the same thing. For example, I have this being called twice. I tried putting the array in the __construct but that didn't work. Any help would be great. Thanks.

Code:
$memProfile = $this->account_details_model->get_member_profile();
                $data['member_info'] = array('member_name' => $memProfile->first_name);

Code:
class App extends Controller {


       function __construct() {

                parent::Controller();
    }
    
    function index() {
        
        $is_logged_in = $this->session->userdata('is_logged_in');
                if (!isset($is_logged_in) || $is_logged_in != true) {
                        redirect('../site/login');

                } else {
                $memProfile = $this->account_details_model->get_member_profile();
                $data['member_info'] = array('member_name' => $memProfile->first_name);

                $data['page'] = array('Dash' => 'current', 'BB' => '', 'BB1' => '', 'BB2' => '', 'BB3' => '', 'BB4' => '', 'CL' => '', 'settings' => '', 'profile' => '' );
                $data['main_content'] = 'app/dashboard_view';
                $this->load->view('app_template/template', $data);

                }
    
    }

       function settings_profile(){
                $memProfile = $this->account_details_model->get_member_profile();
                $data['member_info'] = array('member_name' => $memProfile->first_name);
                
                $data['page'] = array('Dash' => '', 'BB' => '', 'BB1' => '', 'BB2' => '', 'BB3' => '', 'BB4' => '', 'CL' => '', 'settings' => 'current', 'profile' => 'current' );
                $data['main_content'] = 'app/settings_profile_view';
                $this->load->view('app_template/template', $data);
          
       }

}


Messages In This Thread
Repeating Code in Controller - by El Forum - 03-30-2010, 10:26 AM
Repeating Code in Controller - by El Forum - 03-30-2010, 11:49 AM
Repeating Code in Controller - by El Forum - 03-30-2010, 09:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB