Created
August 29, 2011 08:41
-
-
Save ralphsaunders/1178019 to your computer and use it in GitHub Desktop.
Loading a view with templates in Codeigniter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Site extends CI_Controller { | |
/** | |
* Index Page for this controller. | |
* | |
* Maps to the following URL | |
* http://example.com/index.php/site | |
* - or - | |
* http://example.com/index.php/site/index | |
* - or - | |
* Since this controller is set as the default controller in | |
* config/routes.php, it's displayed at http://example.com/ | |
* | |
* So any other public methods not prefixed with an underscore will | |
* map to /index.php/site/<method_name> | |
* @see http://codeigniter.com/user_guide/general/urls.html | |
*/ | |
public function index() | |
{ | |
$todo_list = array( 'milk', 'bread', 'eggs', 'sugar' ); | |
$data['title'] = 'Page Title'; | |
$data['main_content'] = 'welcome'; // "welcome" is the filename of your view | |
$data['todo'] = $todo_list; | |
$this->load->view('template', $data); | |
} | |
} | |
/* End of file site.php */ | |
/* Location: ./application/controllers/site.php */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<title><?php if (isset($title)) { echo $title; } else { echo "Untitled"; } ?></title> | |
<!-- Character Encoding --> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<!-- Favicon --> | |
<link rel="shortcut icon" href="<?php echo base_url(); ?>resources/imgs/favicon.ico" /> | |
<!-- Stylesheets --> | |
<link rel="stylesheet" href="<?php echo base_url(); ?>resources/css/style.css" type="text/css" media="screen"> | |
<!-- jQuery; other scripts are located at the bottom of the page --> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
var baseUrl = "<?php echo base_url(); ?>/"; | |
var siteUrl = "<?php echo site_url(); ?>/"; | |
</script> | |
<!--[if lt IE 9]> | |
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<!-- Humans --> | |
<link rel="author" href="<?php echo base_url(); ?>humans.txt" /> | |
</head> | |
<body id="index"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $this->load->view('header'); ?> | |
<?php $this->load->view($main_content); ?> | |
<?php $this->load->view('footer'); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Ohai</h1> | |
<ul> | |
<?php foreach( $todo_list as $todo ) : ?> | |
<li><?php echo $todo; ?></li> | |
<?php endforeach; ?> | |
</ul> | |
<?php echo date(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you, works great