0

hi this is my controller :

public function index()
    {
        $data['menu'] = $this->load->view('frontend/menu/main_menu_view'); 
        $this->load->view('frontend/header/header_view',$data);
        $this->load->view('frontend/home/index_view');
    }

and this is the code from the index_view view :

echo $menu;

but is not working, what should I do ? thx

4 Answers 4

1

The third parameter of $this->load->view() doesn't load the view but returns it as 'data', to do with it what you please, muwahhahah! Sorry.

$data['menu'] = $this->load->view('frontend/menu/main_menu_view' , '', true); 

You can still pass $data into that view.

So from inside of

$this->load->view('frontend/header/header_view',$data);

you will echo $menu

Scroll to the bottom of the docs

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

1 Comment

This would be the best practice, you might want to create or utilize a template class
1

You can call

$this->load->view('frontend/menu/main_menu_view');

from inside any view file and it will load and display for you.

Comments

0

In the view, you have to write just this :

<?php 
$this->view('frontend/menu/main_menu_view');
?>

Comments

-1

Don't know if you copied this from your code or made a typo while typing your question, here, but shouldn't it be

echo $menu;

instead of

echo menu; ?

edit: Also, haven't worked with Codeigniter in a while, but why pass $data to the header_view and call it from the index_view instead ?

4 Comments

it is not from there :) I forgot to write the $.
I edited my answer. There is that other thing, why not try calling the data['menu'] from the view you attached it to?
it does not matter where i want to pass the variable, neither way is not working! and the echo $menu line, I didn;t want to copy paste from my code , because it was to short and i wrote it by hand :)
please if you have any ideea why is not working, im opened minded, thx :D

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.