Welcome Guest, Not a member yet? Register   Sign In
Preventing DRY in OOP
#1

[eluser]behnampmdg3[/eluser]
I notice I have this in some of my controllers. Exact same code.

How can I move this somewhere else and still be able to simply use the properties (variables).

Thanks
Code:
protected $logged;
protected $unread = 0;
protected $ad_without_photo_found = '';
protected $year = "";
public $email = "";
public function __construct()
{
     parent::__construct();
        if(isset($this->session->userdata['logged_data']['logged_in']))
   {
    if($this->session->userdata['logged_data']['logged_in']!=1 || !is_numeric($this->session->userdata['logged_data']['member_id']))
     {
      redirect(base_url('log_in'), 'refresh');
     }
    
     //Unread Messages
     $data['unread'] = $this->model_ads->unread_messages($this->session->userdata['logged_data']['member_id']);
     $this->unread = $data['unread'][0]->messages;
    
     //Check if Ad with no photo exists
     $data['have_no_photo'] = $this->model_ads->my_haves_no_photo($this->session->userdata['logged_data']['member_id']);
     $data['ad_without_photo_found'] = '';
     foreach($data['have_no_photo'] as $val => $row)
      {
       if($row->PID==0)
       {
        $this->ad_without_photo_found = '<li><a  href="'.base_url('account/index/2').'"><button type="button" class="btn btn-danger">Incomplete Ad found! Click here to resolve.</button></a></li>';
       }
      }
   }
  else
   {
    redirect(base_url('log_in'), 'refresh');
   }
  
}


Messages In This Thread
Preventing DRY in OOP - by El Forum - 01-09-2014, 05:44 AM
Preventing DRY in OOP - by El Forum - 01-09-2014, 10:01 AM
Preventing DRY in OOP - by El Forum - 01-09-2014, 10:33 AM
Preventing DRY in OOP - by El Forum - 01-10-2014, 01:41 AM
Preventing DRY in OOP - by El Forum - 01-10-2014, 05:22 AM
Preventing DRY in OOP - by El Forum - 01-10-2014, 10:11 AM
Preventing DRY in OOP - by El Forum - 01-10-2014, 02:12 PM
Preventing DRY in OOP - by El Forum - 01-11-2014, 05:12 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 05:44 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 05:54 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 06:09 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 06:10 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 06:13 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 06:17 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 06:29 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 06:33 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 07:49 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 07:51 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 07:54 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 09:16 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 09:58 AM
Preventing DRY in OOP - by El Forum - 01-11-2014, 06:09 PM
Preventing DRY in OOP - by El Forum - 01-12-2014, 05:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB