I am new to CI and wanted to get some feed back on my code and just get a feel of where my thought process is and if I am really getting my head wrapped around CI.
I have a file in my core directory called My_Controller which has this code:
<?php
class MY_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->data = array(
'title' => '',
'keywords' => 'default keywords',
'description' => 'default description',
'layout' => 'default',
'view' => '',
'body_class' => '',
'data' => array()
);
}
}
I also have a controller called home in the controller directory with this code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends MY_Controller
{
function __construct()
{
parent::__construct();
}
public function index()
{
/*
Set variables to send to the wrapper template
Default values are stored in /application/core/MY_Controller.php
*/
$this->data['title'] = 'Home';
$this->data['keywords'] = 'Home';
$this->data['description'] = 'Home';
$this->data['view'] = 'content/home';
$this->data['body_class'] = 'home';
$this->data['data'] = array(); // associative array of values you can pass to the view
$this->load->view('layout/default', $this->data);
}
}
**And finally I have a view named default which hold my header and footer info. Now I would like to dynamically load the correct content view depending on where I am in my site. This is what I have for my default view:
<!doctype html>
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="stylesheet" href="/assets/css/reset.css">
<link rel="stylesheet" href="/assets/css/app.common.css">
<script src="/assets/js/libs/modernizr-2.0.6.min.js"></script>
</head>
<body class="<?php echo $body_class; ?>">
<div id="wrapper">
<div id="container">
<header id="header">
<nav>
<ul>
<li>
<a href="/">Home</a>
</li>
</ul>
</nav>
</header>
<section id="main" role="main">
<?php echo $this->load->view($view); ?>
</section>
<footer id="footer"></footer>
</div>
</div>
<!--jQuery Libraries and Plugins-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/js/libs/jquery-1.8.0.min.js"><\/script>')</script>
<!--Other JavaScript Libraries and Plugins-->
<script type="text/javascript"> // Change UA-XXXXX-X to be your site's ID
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!--[if lt IE 9]>
<script src="/js/libs/selectivizr-1.0.2.min.js"></script>
<![endif]-->
<!--Application JavaScript-->
<script src="js/app/app.common.js"></script>
</body>
</html>
I get the correct syntax from home.php but I also get these errors:
** A PHP Error was encountered
Severity: Warning Message: ob_start(): output handler 'ob_gzhandler' conflicts with 'zlib output compression' Filename: core/Output.php Line Number: 379**
** A PHP Error was encountered
Severity: Notice Message: ob_start(): failed to create buffer Filename: core/Output.php Line Number: 379**
Can someone please tell me if I'm missing something or if this is just plain incorrect.