unemployment Posted October 27, 2011 Share Posted October 27, 2011 I’m very new to CF and MVC in general, but I have been writing php for about a year. I was working through a NetTutsPlus tutorial on how to setup a template system and I already hit some road blocks that I have no idea how to solve. I want to use a template because I want to be as efficient as possible. If it helps, here is a link to the tutorial I worked from 1. I don’t know how to change the URL structure. Currently the template system forces me to go to index.php/site/blog for example. 2. I don’t know how to pass in dynamic data to my header and footer using this system. 3. What does extends do? Example: “class Site extends CI_Controller” Here is my current setup… views/template.php <?php $this->load->view('/includes/header'); $this->load->view($main_content); $this->load->view('/includes/footer'); ?> controllers/site.php <?php class Site extends CI_Controller{ function header() { $this->load->library('common'); $page_names = $this->common->pages(); $page = substr(end(explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF'])), 0, -4); $title = (array_key_exists($page, $page_names) !== false) ? $page_names[$page]: ''; if (array_key_exists($page, $page_names) !== false) { $title .= " | Jason Biondo"; } $data['header_content'] = $title; $this->load->view('template', $data); } function about_us() { $data['main_content'] = 'about_us'; $this->load->view('template', $data); } function blog() { $data['main_content'] = 'blog'; $this->load->view('template', $data); } } ?> views/includes/header.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="en" dir="ltr"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="content-script-type" content="text/javascript" /> <title><?php echo $title; ?></title> </head> <body> <div id="container"> Quote Link to comment https://forums.phpfreaks.com/topic/249904-setting-up-my-site-with-code-igniter-template/ Share on other sites More sharing options...
jotorres1 Posted October 27, 2011 Share Posted October 27, 2011 1. For the url structure, I recommend solution 3 on the following link: http://codeigniter.com/wiki/Dreamhost_.htaccess 2. You are passing dynamic data, you are just looking for it wrong. example, you have <?php $data['header_content'] = $title; $this->load->view('template', $data); ?> In order to get this in your view, you would need to call it like this: <title><?php echo $header_content; ?></title> 3. Extends means: you are able to use core codeigniter functions You wouldn't be able to use: <?php $this->load->view(); ?> If you do not 'EXTENDS' the core functionality. Quote Link to comment https://forums.phpfreaks.com/topic/249904-setting-up-my-site-with-code-igniter-template/#findComment-1282792 Share on other sites More sharing options...
samitrimal Posted November 25, 2011 Share Posted November 25, 2011 Use the tempate library by philsturgeon.You can find it in wiki . its really nice Quote Link to comment https://forums.phpfreaks.com/topic/249904-setting-up-my-site-with-code-igniter-template/#findComment-1291138 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.