Pass data to nested view many time within one variable ? |
Best solution to pass data to nested view ?
I research some guide about this, almost they do like this : Class A extends CI_Controller { $this->data['title'] = "WEBSITE"; $view['view_1'] = $this->load->view('view_1', '', TRUE); $view['view_2'] = $this->load->view('view_2', '', TRUE); $this->data['view'] = $view; $this->load->view('main_view', $this->data); } In main_view : <?=view['view_1']?> <?=view['view_2']?> In view_1 <?=$title?> It will get error : Message: Undefined variable: title Because view_1 is not passed data. So, i edit like this: $view['view_1'] = $this->load->view('view_1', $this->data, TRUE); My question : - First : if i pass "$this->data" two times in two views like this => make my website slower ? - Second : have any solution for this case ($this->data have a lot of data may be to use in all views) PHP Code: $this->load->vars($data); Make all variables global to all views. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Thanks for your reply !
My code : Code: $this->data['title'] = "WEBSITE"; But, i still get error when i load main_view : Undefined variable: title (06-15-2016, 08:53 PM)ryantranvn Wrote: Thanks for your reply ! In main view: PHP Code: <?= $this->load->view('view1', '', TRUE) ?> Code to load main view: PHP Code: $this->data['title'] = "WEBSITE";
|
Welcome Guest, Not a member yet? Register Sign In |