php - Using a private variable in a controller -


i'm developing website using codeigniter.

i have declared controller, in controller class added private variable array, , filled array informations session class.

<?php if ( ! defined('basepath')) exit('no direct script access allowed');  class admin extends ci_controller{      public function __construct()     {         private $data  = array('');          parent::__construct();         $this->data = array(             'nom' => $this->session->userdata('admin_fullname')         );     } 

in methods have call variable as:

public function dashboard(){     $this->load->view('admin/header', $data);     $this->load->view('admin/left_navigation');     $this->load->view('admin/dashboard');     $this->load->view('admin/footer'); } 

but gives me error :

#a php error encountered severity: notice message: undefined variable: data filename: controllers/admin.php line number: 73

the line number 73 : $this->load->view('admin/header', $data);

you're declaring private variable within function; you'll have move out.

so this:

class admin extends ci_controller{    public function __construct()   {     private $data  = array('');      parent::__construct();     $this->data = array(         'nom' => $this->session->userdata('admin_fullname')       );   }   

will turn this:

class admin extends ci_controller{    private $data;   public function __construct()   {     $this->$data  = array('');      parent::__construct();     $this->data = array(         'nom' => $this->session->userdata('admin_fullname')       );   }   

also, don't forget access data array prefixing $this->.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -