CodeIgniter Forums
Why doesn't destructor load views? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Why doesn't destructor load views? (/showthread.php?tid=55560)



Why doesn't destructor load views? - El Forum - 11-01-2012

[eluser]behnampmdg3[/eluser]
Hello;

Why cant I load views with destructor?

Thanks
Code:
class Members extends CI_Controller {
public $member_id;
public $email;
public function __construct()
  {
   parent::__construct();
   $data['title'] = "Members Page";
   $this->load->vars($data);
   $this->members();
   $this->places();
  }
public function index()
  {
  
  }
public function members()
  {
   $this->load->model('members_model');
   $data['members'] = $this->members_model->get_all_members();
   $this->load->helper('url');
   $this->load->vars($data);
  }
  
public function places()
  {
   $this->load->model('places_model');
    $data['places'] = $this->places_model->get_all_places();
    $this->load->vars($data);
    //$this->output->enable_profiler(TRUE);
   }
  
  public function send_email()
   {
    if(isset($_POST['email']))
      {
       $this->email = $_POST['email'];
      }
    $this->load->library('form_validation');
    $this->form_validation->set_rules('email','email','required');
   $this->load->helper('email');
    if (valid_email($this->email))
     {
      $this->do_send();
     }
    else
     {
      $this->show_error();
     }
   }
  public function do_send()
   {
    $email_valid = true;
    send_email($this->email, 'From Codeigniters engine', 'YAY');
    $data['form_message'] = "Email has been sent successfully";
    $this->load->vars($data);
   }
  public function show_error()
   {
    $data['form_message'] = "Invalid Email Address";
    $this->load->vars($data);
   }
  
  public function view()
   {
    $this->load->view('header_view');
    $this->load->view('members_view');
    $this->load->view('footer_view');
   }
  
  public function __destruct()
   {
    $this->view();
   }
  
  
}



Why doesn't destructor load views? - El Forum - 11-01-2012

[eluser]solid9[/eluser]
_destructor is just the opposite of _constructor

http://php.net/manual/en/language.oop5.decon.php

study PHP first.


Why doesn't destructor load views? - El Forum - 11-01-2012

[eluser]solid9[/eluser]
Also view is a CodeIgniter reserved word.
Better use another word.