Welcome Guest, Not a member yet? Register   Sign In
loading template only once ?
#5

(This post was last modified: 02-23-2017, 03:19 PM by eduard.pantazi.)

For me worked very well with new Controller, like:

Create a MY_Controller.php in application/core with this:
PHP Code:
<?php

class MY_Controller extends CI_Controller {

function 
__construct() {
parent::__construct();
}

function 
template($pagename$data null) {
$this->load->view('header'$data);
$this->load->view($pagename$data);
$this->load->view('footer'$data);
}



And this is it. To work with it, in your controllers use like this:

PHP Code:
....
class 
MyController extends MY_Controller {

function 
index() {
$data[""hello"] = "Hello passed trough the template() function with the variable $data in template function";
$this->template("pagename", $data);
}

}

... 

Now you have a template function that load the header and footer everytime and also load the page content and you can pass trough data to show on the header,page content and footer. Hope is usefull.


Have a nice day,
Eduard.

Quote:I love web development. I love web design. I love photography.

Reply


Messages In This Thread
loading template only once ? - by Coool6 - 02-22-2017, 07:22 AM
RE: loading template only once ? - by InsiteFX - 02-22-2017, 11:10 AM
RE: loading template only once ? - by Coool6 - 02-22-2017, 12:10 PM
RE: loading template only once ? - by ciadmin - 02-22-2017, 10:06 PM
RE: loading template only once ? - by eduard.pantazi - 02-22-2017, 11:44 PM
RE: loading template only once ? - by InsiteFX - 02-23-2017, 05:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB