Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loading templete in every file ? #3

Closed
mali1991 opened this issue Sep 2, 2013 · 6 comments
Closed

loading templete in every file ? #3

mali1991 opened this issue Sep 2, 2013 · 6 comments

Comments

@mali1991
Copy link

mali1991 commented Sep 2, 2013

Do i have to load the template in every controller .... or there is a way that default template is loaded automatically

@scoumbourdis
Copy link
Owner

Hello there, you can create a BaseController and then extend it. For example: create a file with name base.php at your controllers like this: https://gist.github.com/scoumbourdis/6417186
Then just extend the Base_Controller instead of CI_Controller. In our case a simple example would be

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

//This line code is required in order to work
require(APPPATH . 'controllers/base.php');

class Example extends Base_Controller {

Don't forget to add this line of code in order to make it work:

require(APPPATH . 'controllers/base.php');

as the above example.

What do you think about that?

@mali1991
Copy link
Author

mali1991 commented Sep 8, 2013

well . That's a good idea . but cant we get any functionality in autoload file .Like we load session or grocery crud library in autoload file so we dont have to load it again and again or something like that.

@scoumbourdis
Copy link
Owner

Actually that's a very good idea. I've added an issue for that as a reminder: #4 .

Thanks
Johnny

@zorzis
Copy link

zorzis commented Jan 10, 2014

Hello, any process on that yet?

@scoumbourdis
Copy link
Owner

Not yet :)

@ozturkmtn
Copy link

Hi there,
i add one function to MY_output page. Then i called each controller this function.
for front side and panel side used different sections.
with this function i can send different data to template also.

function load_template($type = NULL){
    $CI =& get_instance ();
    $CI->load->library('menu');
    
    if ($type == 'panel'){
        $section = 'sections/panel';
    }
    if ($type == 'front'){
        $section = 'sections/front';
        $data["menu"] = $CI->menu->front_menu();
    }
    $this->set_template('panel');
    $CI->load->section('head', $section.'/head');
    $CI->load->section('nav', $section.'/nav',$data??"");
    $CI->load->section('footer', $section.'/footer');
}

i can send dynamic menu items to template now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants