Welcome Guest, Not a member yet? Register   Sign In
Issue with include
#2

(This post was last modified: 05-12-2016, 09:56 AM by Wouter60.)

You can load another view inside a view.

View: news/add.php
PHP Code:
<?php $this->load->view('template/header');?>
...
...
<?php $this->load->view('template/footer');?>

This way, though, you get a lot of repeating code. Because every view must embed a header and footer. An alternative way is make a function in MY_Controller (that extends the CI_Controller):

PHP Code:
public function _render_page($view$data) {
$this->load->view('template/header');
$this->load->view($view,$data);
$this->load->view('template/footer');


Now, from your controller, you can do this:
PHP Code:
$this->_render_page('news/add'$data);  //data is an array with variables you want to use in the view 
Reply


Messages In This Thread
Issue with include - by kikk - 05-12-2016, 06:25 AM
RE: Issue with include - by Wouter60 - 05-12-2016, 09:55 AM
RE: Issue with include - by kikk - 05-13-2016, 12:12 AM
RE: Issue with include - by kikk - 05-13-2016, 06:34 AM
RE: Issue with include - by kikk - 05-17-2016, 12:40 AM
RE: Issue with include - by Wouter60 - 05-17-2016, 12:36 PM
RE: Issue with include - by John_Betong - 05-17-2016, 05:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB