codeigniter, passing object to view

2019-05-02 04:18发布

问题:

I have the following in my codeigniter constructor:

$navbar= new stdClass(); 
$navbar->user_email = $this->user_email;
$navbar->vp = $this->vp;

When I try to access this in my index function:

public function index() {

     var_dump($this->navbar);

this works.

I now tried to pass $this->navbar to the view with:

$this->load->view('buyers/navbar', $this->navbardata);

In the view I have

<?php echo 'in nav ';var_dump($this->navbar); exit; ?>

I get :

Message: Undefined property: MY_Loader::$navbar    

How can I make this work?

Thanks in advance,

回答1:

Try like this

$data['navbar'] = $this->navbardata;
$this->load->view('buyers/navbar', $data);

and in your view try like

<?php echo 'in nav ';var_dump($navbar); exit; ?>