0

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

  1. I am calling the header (which has css,js files)

  2. I am calling the view index and sending the value $data into it

  3. 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);
}

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.