[eluser]john.weland[/eluser]
So after a lot of thought, and input, and such I decided to build my blog based on a single table and categories.
What I mean is write all my articles to an article database and if the category is = blog then all that data shows on the blog page and if category data = news all that data shows on the news page. I was informed that this was the more difficult of the two routes but I've also been told its the better structure for 'future proofing'.
My Controller
Code:
<?php
class Site extends CI_Controller{
function index()
{
redirect('site/news');
}
function news() {
$data['main_content'] = 'news';
$this->load->view('template', $data);
}
function about() {
$data['main_content'] = 'about';
$this->load->view('template', $data);
}
function resume() {
$data['main_content'] = 'resume';
$this->load->view('template', $data);
}
function blog() {
$data['main_content'] = 'blog';
$this->db->where('categories_id', 2);
$data['$query'] = $this->db->get('articles');
$this->load->view('template', $data);
}
function projects() {
$data['main_content'] = 'projects';
$this->load->view('template', $data);
}
function forums() {
$data['main_content'] = 'forums';
$this->load->view('template', $data);
}
}
My Blog View
Code:
<title>Blog</title>
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<?php if ($query->num_rows() > 0): ?>
<?php foreach($query->result() as $row): ?>
<h3><?=$row->title?></h3>
<p><?=$row->body?></p>
<hr>
<?php endforeach; ?>
<?php endif; ?>
</div>
<p class="stats">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
if you look at my controller page you'll see its setup for a template system if you look at "function blog" I think you can see what I am trying to accomplish. if the categories_id = 2 (2 is the blog category) load any articles with a category_id value of 2.
My blog view gives me an error at line 7
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined variable: query
Filename: views/blog.php
Line Number: 7
codeigniter 2.1.3