We have a list of public articles; let's create a list of draft
articles. This will be very similar to the index
action and view.
Open the Blog.php
page controller
class file. (In this example we use the vim
editor, but you can use anything you like.)
$ vim Blog.php
Add the following PHP code to the class.
<?php
public function actionDrafts()
{
// draft blog articles in ascending order, all result pages
$fetch = array(
'where' => array('blogs.status = ?' => 'draft'),
'order' => 'blogs.created ASC',
'page' => 'all',
);
// fetch all matching records
$this->list = $this->_model->blogs->fetchAll($fetch);
}
Create a view called drafts.php
for the
actionDrafts()
method.
$ vim Blog/View/drafts.php
Enter the following code in the new drafts.php
view script.
<?php
$title = $this->getTextRaw('TITLE_DRAFTS');
$this->head()->setTitle($title);
?>
<h2><?php echo $this->getText('HEADING_DRAFTS'); ?></h2>
<?php if (! $this->list): ?>
<p><?php echo $this->getText('ERR_NO_RECORDS'); ?></p>
<?php else: ?>
<ul>
<?php foreach ($this->list as $item): ?>
<li><?php
echo $this->escape($item->title);
echo " ";
echo $this->action(
"{$this->controller}/edit/{$item->id}",
'ACTION_EDIT'
);
?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<p><?php echo $this->action(
"{$this->controller}/add",
'ACTION_ADD'
); ?></p>
This view shows a list of draft articles stored in
$this->list
along with a link to edit each one.
At the bottom of the page is a link to add a new article.
You should now be able to browse to http://localhost/index.php/blog/drafts to see this page.