CREATE TABLE `guestbook` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(16) default NULL,
`message` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=1 ;
/application/models/Guestbook.php
<?php
class Guestbook extends Zend_Db_Table
{
protected $_name = 'guestbook';
}
/application/controllers/IndexController.php
<?php
class IndexController extends Zend_Controller_Action
{
function indexAction(){
$gb = new Guestbook();
$num = 10;
$page = $this->_getParam('page');
if($page<1 or empty($page)){$page = 1;}
$select = $gb->select()->from('guestbook',array('count'=>'COUNT(*)'))->order('id DESC ');
$total = $this->view->table = $gb->fetchRow($select)->toArray();
$start = $page*$num-$num;
$select = $gb->select()->from('guestbook')->order('id DESC ')->limit($start,$num);
$result = $this->view->table = $gb->fetchAll($select)->toArray();
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_array($result));
$paginator->setCurrentPageNumber($this->_getParam($page));
$paginator->setItemCountPerPage($num);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('/my_pagination.phtml');
$this->view->paginator = $paginator;
}
function addAction(){
if($this->_request->isPost()){
$filter = new Zend_Filter_StripTags();
$name = trim($filter->filter($this->_request->getPost('name')));
$message = trim($filter->filter($this->_request->getPost('message')));
if(!empty($name) && !empty($message)){
$data = array(
'name' => $name,
'message' => $message
);
$gb = new Guestbook();
$gb->insert($data);
$this->_redirect('/');
}
} else $this->view->errorMessage = " , .";
}
function init(){
Zend_Loader::loadClass('Zend_Filter_StripTags');
Zend_Loader::loadClass('Guestbook');
Zend_Loader::loadClass('Zend_Paginator');
Zend_Loader::loadClass('Zend_Paginator_Adapter_array');
Zend_Loader::loadClass('Zend_View_Helper_PaginationControl');
}
}
$gb = new Guestbook();
$num = 10;
$page = $this->_getParam('page');
if($page<1 or empty($page)){$page = 1;}
$select = $gb->select()->from('guestbook',array('count'=>'COUNT(*)'))->order('id DESC ');
$total = $this->view->table = $gb->fetchRow($select)->toArray();
$start = $page*$num-$num;
$select = $gb->select()->from('guestbook')->order('id DESC ')->limit($start,$num);
$result = $this->view->table = $gb->fetchAll($select)->toArray();
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_array($result));
$paginator->setCurrentPageNumber($page)
$paginator->setView($this->view);
$paginator->setItemCountPerPage($num);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('/my_pagination.phtml');
$this->view->paginator = $paginator;
/application/scripts/index/index.phtml
<?php
if (count($this->paginator)): ?>
<?php foreach ($this->paginator as $item):?>
<?= $item['name']; ?><br>
<?= $item['message']; ?>
<?php endforeach; ?>
<?php endif; ?>
<?= $this->paginationControl($this->paginator, 'Sliding', '/my_pagination.phtml'); ?>
/application/scripts/index/index.phtml
<?php
if (count($this->paginator)): ?>
<?php foreach ($this->paginator as $item):?>
<?= $item['name']; ?><br>
<?= $item['message']; ?>
<?php endforeach; ?>
<?php endif; ?>
<?= $this->paginationControl($this->paginator, 'Sliding', '/my_pagination.phtml'); ?>
<?= $this->paginationControl($this->paginator, 'Sliding', '/my_pagination.phtml'); ?>
/application/scripts/my_pagination.phtml
<?php
if ($this->pageCount): ?>
<?php if (isset($this->previous)): ?>
< Previous |
<?php else: ?>
< Previous |
<?php endif; ?>
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<?= $page; ?> |
<?php else: ?>
<?= $page; ?> |
<?php endif; ?>
<?php endforeach; ?>
<?php if (isset($this->next)): ?>
><?php else: ?>
<?php endif; ?>
<?php endif; ?>
$this->pageCount β $this->previous β $this->current β $this->next β
<a href="<?=$this->url(array('page' => $this->next)); ?>">>
, url(), , .
, , . , , Zend Framework.
/application/scripts/my_pagination.phtml
<?php
if ($this->pageCount): ?>
<?php if (isset($this->previous)): ?>
< Previous |
<?php else: ?>
< Previous |
<?php endif; ?>
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<?= $page; ?> |
<?php else: ?>
<?= $page; ?> |
<?php endif; ?>
<?php endforeach; ?>
<?php if (isset($this->next)): ?>
><?php else: ?>
<?php endif; ?>
<?php endif; ?>
$this->pageCount β $this->previous β $this->current β $this->next β
<a href="<?=$this->url(array('page' => $this->next)); ?>">>
, url(), , .
, , . , , Zend Framework.
/application/scripts/my_pagination.phtml
<?php
if ($this->pageCount): ?>
<?php if (isset($this->previous)): ?>
< Previous |
<?php else: ?>
< Previous |
<?php endif; ?>
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<?= $page; ?> |
<?php else: ?>
<?= $page; ?> |
<?php endif; ?>
<?php endforeach; ?>
<?php if (isset($this->next)): ?>
><?php else: ?>
<?php endif; ?>
<?php endif; ?>
$this->pageCount β $this->previous β $this->current β $this->next β
<a href="<?=$this->url(array('page' => $this->next)); ?>">>
, url(), , .
, , . , , Zend Framework.
/application/scripts/my_pagination.phtml
<?php
if ($this->pageCount): ?>
<?php if (isset($this->previous)): ?>
< Previous |
<?php else: ?>
< Previous |
<?php endif; ?>
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<?= $page; ?> |
<?php else: ?>
<?= $page; ?> |
<?php endif; ?>
<?php endforeach; ?>
<?php if (isset($this->next)): ?>
><?php else: ?>
<?php endif; ?>
<?php endif; ?>
$this->pageCount β $this->previous β $this->current β $this->next β
<a href="<?=$this->url(array('page' => $this->next)); ?>">>
, url(), , .
, , . , , Zend Framework.
/application/scripts/my_pagination.phtml
<?php
if ($this->pageCount): ?>
<?php if (isset($this->previous)): ?>
< Previous |
<?php else: ?>
< Previous |
<?php endif; ?>
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<?= $page; ?> |
<?php else: ?>
<?= $page; ?> |
<?php endif; ?>
<?php endforeach; ?>
<?php if (isset($this->next)): ?>
><?php else: ?>
<?php endif; ?>
<?php endif; ?>
$this->pageCount β $this->previous β $this->current β $this->next β
<a href="<?=$this->url(array('page' => $this->next)); ?>">>
, url(), , .
, , . , , Zend Framework.
/application/scripts/my_pagination.phtml
<?php
if ($this->pageCount): ?>
<?php if (isset($this->previous)): ?>
< Previous |
<?php else: ?>
< Previous |
<?php endif; ?>
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<?= $page; ?> |
<?php else: ?>
<?= $page; ?> |
<?php endif; ?>
<?php endforeach; ?>
<?php if (isset($this->next)): ?>
><?php else: ?>
<?php endif; ?>
<?php endif; ?>
$this->pageCount β $this->previous β $this->current β $this->next β
<a href="<?=$this->url(array('page' => $this->next)); ?>">>
, url(), , .
, , . , , Zend Framework.
Source: https://habr.com/ru/post/44422/
All Articles