Welcome Guest, Not a member yet? Register   Sign In
How do I have a global array in __construct() ?

I would advise you, stop what you are doing and please read up on basic OOP and PHP.
What you are asking is basic OOP knowledge. If you don't have that you are going to keep making the same mistakes over and over without even knowing it.

To help you out now
You declare global variables outside of any method. That includes the constructor!

PHP Code:
('BASEPATH') OR exit('No direct script access allowed');

Main extends MY_Controller {

   // Declare all global variables here 
   public $notification = array();
   public $data;
   public $me;

   public function __construct()

       if( isset($this->me) ) { $data['me'] = $this->me$me $this->me; }

       $this->notification $this->db->query("SELECT * FROM posts WHERE noti_recipient = '$me[id]' && noti_read = 'no' && userid != '$me[id]' ORDER BY datetimesecondnumber DESC LIMIT 1 ")->row_array();
       if( isset($this->notification) ) { $this->data['notification'] = $this->notification$this->me $this->notification; } // WHY???


Your code is very messy. Look into using models. You shouldn't write queries in the constructor of a Controller

Messages In This Thread
RE: How do I have a global array in __construct() ? - by Martin7483 - 08-03-2017, 06:15 AM

Theme © iAndrew 2016 - Forum software by © MyBB