Reputation: 11
Hey guys, I'm having an issue with loading multiple views in codeigiter.
$this->load->view('header');
$this->load->view('body-view', $data);
$this->load->view('footer');
The code above will allow me to load views right after each other on other servers I have worked on. For some reason, my server will only ouput one of these views at a time. I have been using codeigniter for a few years now, so I know that this is valid syntax.
Could it be an output issue with my servers configuration? Any help is much appreciated.
Upvotes: 0
Views: 12084
Reputation: 26
I guess you are not passing true parameter while passing view file.
please refer bellow tricks:
$output = $this->load->view('your_view', 'your_data', true);
$output .= $this->load->view('your_other_view', 'your_other_data', true);
$output .= $this->load->view('your_last_view', 'your_last_data', true);
$this->output->set_output($output);
**Second Method, you can be passing view with data like :**
$data['header'] = $this->load->view('your_header_view_file_name', true);
$data['footer'] = $this->load->view('your_footer_view_file_name', true);
$data['your_necessary_data'] = $your variables ;
$data['your_necessary_data2'] = $your variables ;
$this->load->view('blogview',$data);
Upvotes: 0
Reputation: 11
I resolved the issue. Some how i guess the package of codeigniter must have gotten corrupted. I just reconfigured codeigniter all over again with a fresh downloaded version and my code worked perfectly.
Upvotes: 1
Reputation: 19882
Instead try this approach
$view = $this->load->view('header',array(),TRUE);
$view .= $this->load->view('body-view', $data , TRUE );
$view .= $this->load->view('footer',array(),TRUE);
echo $view;
Also check your html syntex it might be causing problem when loading multiple views. Please validate your html and try again.
Upvotes: 0