Funkcja służąca za dodawanie do bazy:
<?php
function addAction() {
$this->view->title = "Dodaj ogłoszenie";
if ($this->_request->isPost()) {
$filter = new Zend_Filter_StripTags();
$title = trim($filter->filter($this->_request
->getPost('title'))); $content = nl2br($this->_request
->getPost('content')); $telephone = trim($filter->filter($this->_request
->getPost('telephone')));
if ($title != '' && $content != '') {
$data = array('title' => $title, 'content' => $content, 'telephone' => $telephone, 'date' => $date, ); $announcements = new announcements();
$announcements->insert($data);
$this->_redirect('/index/announcements');
return;
}
}
$this->view->announcements = new stdClass();
$this->view->announcements->id = null;
$this->view->announcements->title = '';
$this->view->announcements->content = '';
$this->view->announcements->telephone = '';
$this->view->announcements->time = '';
$this->view->action = 'add';
$this->view->buttonText = 'Dodaj';
}
?>
Formularz dodający:
<form action="
<?php echo $this->baseUrl; ?>/index/
<?php echo $this->action; ?>" method="post">
<input type="hidden" name="id" value="
<?php echo $this->album->id; ?>" />
<strong>Tytuł:</strong><br /><input type="text" name="title" /><br /><br />
<strong>Opis:</strong><br /><textarea name="content"></textarea><br /><br />
<strong>Telefon:</strong><br /><input type="text" name="telephone" /><br /><br />
<input type="submit" name="add" value="
<?php echo $this->escape($this->buttonText); ?>" />
</form>
Funkcja służąca za odczytywanie:
<?php
function showAction() {
$this->view->title = "Ogłoszenia";
$id = (int)$this->_request->get('id');
$announcements = new announcements();
$where = 'id ='. $id;
$select = $announcements->select()->where($where);
$this->view->row_show = $announcements->fetchRow($select);
}
?>
Widok - odczytywanie:
<strong>Tytuł:</strong>
<?php echo $this->escape($this->row_show->title); ?><br /><br />
<strong>Data dodania:</strong>
<?php $date = $this->escape($this->row_show->date); echo date('d.m.Y, H:i', $date); ?><br /><br />
<strong>Telefon:</strong>
<?php echo $this->escape($this->row_show->telephone); ?><br /><br />
<strong>Opis:</strong>
<?php echo $this->escape($this->row_show->content); ?>
Chciałbym jeszcze zabezpieczyć w tej pierwszej funkcji zmienną content tym flitrem, ale tak, żeby mi tego <br /> nie usunęło.
Z góry dzięki za pomoc.