Reputation: 889
Hi Here is my Loader and Index Function inside my Controller
While calling the index() function I am assigning the $menu['menu'] and $menu['menu'] at the same time i am the value for $data and sending it to the loader function.
In the Loader function
I am calling the header (which has css,js files)
I am calling the view index and sending the value $data into it
I am calling the footer
But in the index view even i didn't send the value $menu, i am able to print the $menu and $title but i can't able to print the $data.
What is the mistake i am doing. How can i get the value of $data inside the index view
Here is my Code :
public function loader($url,$menu,$data)
{
$this->load->view('assets/header',$menu);
$this->load->view($url,$menu,$data);
$this->load->view('assets/footer');
}
public function index()
{
$menu['menu']="home";
$menu['title']="Home Page";
$data='somedata';
$this->loader('index',$menu,$data);
}
Upvotes: 0
Views: 39
Reputation: 7134
When you pass value at view you should pass it as array and the array key will be received as variable at view.In your case you need to replace the line $data='somedata'
with;.
$menu['data']='somedata';
You will receive it as $data inside view
You also need to rewrite the line $this->load->view($url,$menu,$data);
like this
$this->load->view($url,$menu);
3rd parameter of load->view function is either true or false;
you can see documentaion
Upvotes: 1