The Database news table:
Code:
CREATE TABLE news (
id int(11) NOT NULL AUTO_INCREMENT,
title varchar(128) NOT NULL,
slug varchar(128) NOT NULL,
text text NOT NULL, <----------> This should be changed to body, text is a MySQL reserved word.
PRIMARY KEY (id),
KEY slug (slug)
);
The view:
PHP Code:
<h2><?= $title ?></h2>
<?php if (! empty($news) && is_array($news)) : ?>
<?php foreach ($news as $news_item): ?>
<h3><?= $news_item['title'] ?></h3>
<div class="main">
<?= $news_item['text'] ?> <--------> Change to body.
</div>
<p><a href="<?= '/news/'.$news_item['slug'] ?>">View article</a></p>
<?php endforeach; ?>
<?php else : ?>
<h3>No News</h3>
<p>Unable to find any news for you.</p>
<?php endif ?>
Also there is an error in the controlllers view method.
PHP Code:
if (empty($data['news']))
{
throw new \CodeIgniter\PageNotFoundException('Cannot find the page: '. $slug);
}
// Should be
if (empty($data['news']))
{
throw new \CodeIgniter\Exceptions\PageNotFoundException('Cannot find the page: '. $slug);
}
view.php
Code:
<?php
echo '<h2>'.$news['title'].'</h2>';
echo $news['text']; <--------------------> Should be body
Also it seems that none of the News Routes are working at all just getting 404's
If I change the routes from the get to the add then they work.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )