Type of Flash Messenger in Zend - zend-framework

Is it possible or How can i give a type to a FlashMessage in Zend?
For example
/* This is a "Success" message */
$this -> _helper -> FlashMessenger('You are successfully created a post.');
/* This is an "Error" message */
$this -> _helper -> FlashMessenger('There is an error while creating post.');
/* This is just a "Notification" message */
$this -> _helper -> FlashMessenger('Now you can see your Post');

I think the best way to do this is by using the flashmessenger namespaces:
/* success message */
$this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Post created!');
/* error message */
$this->_helper->FlashMessenger()->setNamespace('error')->addMessage('You have no permissions');
And then in your layout you can get the messages added to each namespace:
<?php $flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
<?php if ($flashMessenger->setNamespace('success')->hasMessages()): ?>
<div class="message success">
<?php foreach ($flashMessenger->getMessages() as $msg): ?>
<?php echo $msg ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($flashMessenger->setNamespace('error')->hasMessages()): ?>
<div class="message error">
<?php foreach ($flashMessenger->getMessages() as $msg): ?>
<?php echo $msg ?>
<?php endforeach; ?>
</div>
<?php endif; ?>

At one time you used assoc arrays to do this... Im not ure if this is still current or not...
/* This is a "Success" message */
$this -> _helper -> FlashMessenger(array('success' => 'You are successfully created a post.'));
/* This is an "Error" message */
$this -> _helper -> FlashMessenger(array('error' => 'There is an error while creating post.'));
/* This is just a "Notification" message */
$this -> _helper -> FlashMessenger(array('notice' => 'Now you can see your Post'));

It is possible. Sample implementation in described in this blog post:
Zend Framework: View Helper Priority Messenger | emanaton
Excerpt:
class AuthController extends Zend_Controller_Action {
function loginAction() {
. . .
if ($this->_request->isPost()) {
$formData = $this->_request->getPost();
if ($this->view->form->isValid($formData)) {
. . .
} else {
$this->view->priorityMessenger('Login failed.', 'error');
}
. . .
}
}

Method signatures in Zend Framework 1.12.x for FlashMessenger:
public function addMessage($message, $namespace = null)
public function getMessages($namespace = null)
public function hasMessages($namespace = null)
public function clearMessages($namespace = null)
So to set messages the following will work:
/* success message */
$this->_helper->flashMessenger()->addMessage('Post created!', 'success');
/* error message */
$this->_helper->flashMessenger()->addMessage('You have no permissions', 'error');
And for the view, the following should work:
<?php $flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
<?php if ($flashMessenger->hasMessages('success')): ?>
<div class="message success">
<?php foreach ($flashMessenger->getMessages('success') as $msg): ?>
<?php echo $msg ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($flashMessenger->hasMessages('error')): ?>
<div class="message error">
<?php foreach ($flashMessenger->getMessages('error') as $msg): ?>
<?php echo $msg ?>
<?php endforeach; ?>
</div>
<?php endif; ?>

Related

zend paginator invalid url

I trying use zend paginator in my project.
And i have problem-when i trying use paginator in news controller, i have links in paginator on index controller!
<?php
class NewsController extends Zend_Controller_Action
{
/**
*
* #var Model_News_Gateway
*/
protected $_newsGateway;
protected $_newsPerPage = 10;
public function init()
{
$this->_newsGateway = new Model_News_Gateway();
}
public function indexAction()
{
$crit = new ExtZF_Model_Criteria();
$crit->addWhere('active', true);
$crit->addDescOrderBy('publish_date');
$paginator = new Zend_Paginator($this->_newsGateway->getPaginatorAdapter($crit));
$paginator->setCurrentPageNumber($this->_getParam('page', 0));
$paginator->setItemCountPerPage($this->_newsPerPage);
$this->view->paginator = $paginator;
}
In view
$this->paginationControl($this->paginator, 'Sliding', '_partials/paginator/default.phtml');
And in default
<?php if ($this->pageCount && count($this->pagesInRange) > 1): ?>
<!--noindex-->
<div class="paginationControl">
(<?= $this->firstItemNumber ?>-<?= $this->lastItemNumber?>/<?= $this->totalItemCount ?>)
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('page' => $this->previous)); ?>">
< <?= $this->translate('previous') ?>
</a> |
<?php else: ?>
<span class="disabled">< <?= $this->translate('previous') ?></span> |
<?php endif; ?>
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<a href="<?php echo $this->url(array('page' => $page)); ?>">
<?php echo $page; ?>
</a> |
<?php else: ?>
<?php echo $page; ?> |
<?php endif; ?>
<?php endforeach; ?>
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url(array('page' => $this->next)); ?>">
<?= $this->translate('next') ?> >
</a>
<?php else: ?>
<span class="disabled"><?= $this->translate('next') ?> ></span>
<?php endif; ?>
</div>
<!--/noindex-->
<?php endif; ?>
I am trying use one default paginator for don't same controllers, but i always have links in paginator like /index/index/page/2.
I need links like /news/index/page/2
But i always have links /index/index/page/2
And i in news controller now. I don't understand why it don't work.
<?
//Ужасный хак, мне стыдно за него
$controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
function replaceController ($search, $replace, $text)
{
$pos = strpos($text, $search);
$secondPos =strpos ($text, $search, $pos+1);
if ($secondPos !== false) {
return $pos !== false ? substr_replace($text, $replace, $pos, strlen($search)) : $text;
} else {
return $text;
}
}
?>

Show post title and custom fields in sidebar with shortcode in widget - Wordpress

I would like to show certain data in the HTML/text widget with shortcodes.
I already made the include php call in my functions.php:
function event_widget($atts) {
// turn on output buffering to capture script output
ob_start();
// include file (contents will get saved in output buffer)
include("wp-content/themes/mytheme/widgets/event.php");
// save and return the content that has been output
$content = ob_get_clean();
return $content;
}
//register the Shortcode handler
add_shortcode('event', 'event_widget');
It gets the data to the widget if I put just plain text to event.php, so the call is done correctly, but I don't know how to write the event.php to get this data:
// the loop
<?php if (have_posts()) :
while (have_posts()) : the_post(); ?>
<ul>
<li>
<?php if( get_post_meta($post->ID, "customfield1", true) ): ?>
<?php echo get_post_meta($post->ID, "customfield1", true); ?>
<?php endif; ?>
</li>
<li>
<?php if( get_post_meta($post->ID, "customfield2", true) ): ?>
<?php echo get_post_meta($post->ID, "customfield2", true); ?>
<?php endif; ?>
</li>
</ul>
Try this:
global $post;
echo get_post_meta($post->ID, "customfield1", true);
echo get_post_meta($post->ID, "customfield2", true);
If you echo a value that is false it will amount to '' (nothing) so you don't have to check if they are set.
And also this works perfect:
<?php
global $post;
$args = array('category' => 37, 'post_type' => 'post' );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
?>
<?php if( get_post_meta($post->ID, "customfield1", true) ): ?>
<?php echo get_post_meta($post->ID, "customfield1", true); ?></span>
<?php endif; ?>
Is anything "wrong" with this code?

ZF2 How to set search form in layout

What is the right way to set a (search) form with Zend Framework 2 in the layout.ptml who is visible on any page of the website?
Thanks in advance.
Nick
It is really simple to set any variables to all layouts in ZF2 by EventManager, just attach the EVENT_RENDER event such as:
class Module
{
public function onBootstrap($e)
{
$app = $e->getParam('application');
$app->getEventManager()->attach(MvcEvent::EVENT_RENDER, array($this, 'setFormToView'), 100);
}
public function setFormToView($event)
{
$form = new MyForm();
$viewModel = $event->getViewModel();
$viewModel->setVariables(array(
'form' => $form,
));
}
}
For view in layout use:
<?php if ($user = $this->identity()): ?>
<?php echo 'Login with user' . $this->escapeHtml($user->nome); ?>
| <?php echo $this->translate('Sair'); ?>
<?php else: ?>
<?php
echo $this->form()->openTag($form);
echo "<h5>Forneça seu login e senha </h5>";
echo $this->formRow($form->get('username'));
echo $this->formRow($form->get('password'));
echo $this->formRow($form->get('rememberme'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>
<?php endif; ?>

Creating child CMS pages in Magento

I would like to create a subordinate set of CMS pages in Magento so that the breadcrumb navigation at the top of the page looks like this:
Home > Parent CMS Page > Child CMS Page
Even though I can specify a hierarchical relationship with the URL key field, it seems to be that all CMS pages in Magento are listed in the root directory by default:
Home > Child CMS Page
Any ideas?
You are right, there is no hierarchy of CMS pages in Magento. The best solution would be to create a real hierarchy by adding a parent_id to CMS pages and modifying the CMS module to handle nested URLs and breadcrumbs. But that requires a lot of coding.
A quick-and-dirty hack is to modify the breadcrumbs manually on each subpage by adding something like this to the layout update XML:
<reference name="root">
<action method="unsetChild"><alias>breadcrumbs</alias></action>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
<action method="addCrumb">
<crumbName>home</crumbName>
<crumbInfo><label>Home page</label><title>Home page</title><link>/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>myparentpage</crumbName>
<crumbInfo><label>My Parent Page</label><title>My Parent Page</title><link>/myparentpage/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>mysubpage</crumbName>
<crumbInfo><label>My Sub Page</label><title>My Sub Page</title></crumbInfo>
</action>
</block>
</reference>
I had the same problem with breadcrumbs and cms pages a few days ago check here ->
Similar to Anders Rasmussen post I edited every cms page manually
In breadcrumbs.phtml I added a little condition to define if a Page is a CMS page (thanks to Alan Storm) and remove standard crumb(s) and added new crumbs via xmllayout.
<?php
if($this->getRequest()->getModuleName() == 'cms'){
unset($crumbs['cms_page']);
}
?>
xml:
<reference name="breadcrumbs">
<action method="addCrumb">
<crumbName>cms_page_1st_child</crumbName>
<crumbInfo><label>1st child</label><title>1st child</title><link>/1st child/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>cms_page_2nd_child</crumbName>
<crumbInfo><label>2nd child</label><title>2nd child</title></crumbInfo>
</action>
</reference>
hope that helps,
Rito
For enterprise (version 1.12) use this code at following file, location is:
default->template->page->html->breadcrumb.phtml.
<?php
$cms_id = Mage::getSingleton('cms/page')->getPageId();
if($cms_id):
if($_SERVER['REQUEST_URI']) {
$trim_data = substr($_SERVER['REQUEST_URI'],1);
$data = explode('/',$trim_data);
}
$cms_collection = array();
$url_full = '';
$cms_enterprise = '';
foreach($data as $identifier) {
$page_data = Mage::getModel('cms/page')->getCollection()
->addFieldToFilter('identifier', $identifier);
if($page_data) {
foreach($page_data as $single) {
if($single->getContentHeading() != null) {
if($single->getPageId()) {
$cms_enterprise = Mage::getModel('enterprise_cms/hierarchy_node')->getCollection()
->addFieldToFilter('page_id', $single->getPageId());
foreach($cms_enterprise as $single_enterprise) {
$url_full = $single_enterprise->getRequestUrl();
}
}
$cms_collection[] = array($single->getTitle(), $single->getContentHeading(), $url_full );
} else {
if($single->getPageId()) {
$cms_enterprise = Mage::getModel('enterprise_cms/hierarchy_node')->getCollection()
->addFieldToFilter('page_id', $single->getPageId());
foreach($cms_enterprise as $single_enterprise) {
$url_full = $single_enterprise->getRequestUrl();
}
}
$cms_collection[] = array($single->getTitle(), $single->getTitle(), $url_full );
}
}
}
}
$count = count($cms_collection);
$i = 1;
?>
<?php if(count($cms_collection)): ?>
<div class="breadcrumbs">
<ul>
<li>
<a href="<?php echo $this->getUrl() /*Home*/ ?>" title="<?php echo $this->__('Home'); /*Home Title*/ ?>">
<?php echo $this->__('Home'); /*Home Name*/ ?>
</a>
<span>> </span>
</li>
<?php foreach($cms_collection as $key=>$value): ?>
<?php if($i == $count): ?>
<li>
<strong>
<?php echo $value[1]; /*Name*/ ?>
</strong>
</li>
<?php else: ?>
<li>
<a href="<?php echo $this->getUrl().$value[2] /*Identifier*/ ?>" title="<?php echo $value[0] /*Title*/ ?>">
<?php echo $value[1]; /*Name*/ ?>
</a>
<span>> </span>
</li>
<?php endif; ?>
<?php $i++; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php else: ?>
<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
<ul>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<li class="<?php echo $_crumbName ?>">
<?php if($_crumbInfo['link']): ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<span>> </span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
Thanks,
Kashif
This is my solution of the problem. I use custom layout for most of the CMS pages (default/template/page/cmsLayout.phtml) so I heve added following code into the layout file:
<div class="col-main">
<?php
$urlPart=str_replace(Mage::getUrl(),'',Mage::getUrl('', array('_current' => true,'_use_rewrite' => true)));
$urlPart=explode('/',$urlPart);
$string='';
$return='<div class="breadcrumbs"><ul><li class="home">Home<span> / </span></li>';
$count=count($urlPart);
foreach($urlPart as $value)
{
$count--;
$string.='/'.$value;
$string=trim($string, '/');
$pageTitle = Mage::getModel('cms/page')->load($string, 'identifier')->getTitle();
if($count==0)
$return.='<li><strong>'.$pageTitle.'</strong></li>';
else
$return.='<li>'.$pageTitle.'<span> / </span></li>';
}
echo $return.'</li></ul></div>';
?>
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
update
-oops- this might be an enterprise feature only
There is a built-in CMS page hierarchy option in Magento.
To turn it on:
System > Configuration > General > Content Management > CMS Page Hierarchy - see here
To organise the hierarchy tree:
CMS > Pages > Manage Hierarchy
To manage the position of a page in the tree, after saving a page, go to its "hierarchy tab" - see the screenshot:
In the example the page "Our culture" is a child of "jobs" and not of the root directory
For Magento Enterprise, I have created an extension to solve this. It uses the built in CMS Hierarchy in the backend. The module is called Demac/BananaBread and shouldn't require any hacks or customization.
Direct download: here
Link to article: http://www.demacmedia.com/magento-commerce/introducing-demac_bananabread-adding-cms-breadcrumbs-from-the-hierarchy-in-magento/
I built a custom block as to generate the crumbs (removing the built-in and replacing with the custom one below in the layout):
namespace Uprated\Theme\Block\Html;
class UpratedBreadcrumbs extends \Magento\Framework\View\Element\Template
{
/**
* Current template name
*
* #var string
*/
public $crumbs;
protected $_template = 'html/breadcrumbs.phtml';
protected $_urlInterface;
protected $_objectManager;
protected $_repo;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\UrlInterface $urlInterface,
\Magento\Framework\ObjectManagerInterface $objectManager,
array $data = [])
{
$this->_urlInterface = $urlInterface;
$this->_objectManager = $objectManager;
$this->_repo = $this->_objectManager->get('Magento\Cms\Model\PageRepository');
$this->getCrumbs();
parent::__construct($context, $data);
}
public function getCrumbs() {
$baseUrl = $this->_urlInterface->getBaseUrl();
$fullUrl = $this->_urlInterface->getCurrentUrl();
$urlPart = explode('/', str_replace($baseUrl, '', trim($fullUrl, '/')));
//Add in the homepage
$this->crumbs = [
'home' => [
'link' => $baseUrl,
'title' => 'Go to Home Page',
'label' => 'Home',
'last' => ($baseUrl == $fullUrl)
]
];
$path = '';
$numParts = count($urlPart);
$partNum = 1;
foreach($urlPart as $value)
{
//Set the relative path
$path = ($path) ? $path . '/' . $value : $value;
//Get the page
$page = $this->getPageByIdentifier($path);
if($page) {
$this->crumbs[$value] = [
'link' => ($partNum == $numParts) ? false : $baseUrl . $path,
'title' => $page['title'],
'label' => $page['title'],
'last' => ($partNum == $numParts)
];
}
$partNum++;
}
}
protected function getPageByIdentifier($identifier) {
//create the filter
$filter = $this->_objectManager->create('Magento\Framework\Api\Filter');
$filter->setData('field','identifier');
$filter->setData('condition_type','eq');
$filter->setData('value',$identifier);
//add the filter(s) to a group
$filter_group = $this->_objectManager->create('Magento\Framework\Api\Search\FilterGroup');
$filter_group->setData('filters', [$filter]);
//add the group(s) to the search criteria object
$search_criteria = $this->_objectManager->create('Magento\Framework\Api\SearchCriteriaInterface');
$search_criteria->setFilterGroups([$filter_group]);
$pages = $this->_repo->getList($search_criteria);
$pages = ($pages) ? $pages->getItems() : false;
return ($pages && is_array($pages)) ? $pages[0] : [];
}
Then used a slightly modified .phtml template to display them:
<?php if ($block->crumbs && is_array($block->crumbs)) : ?>
<div class="breadcrumbs">
<ul class="items">
<?php foreach ($block->crumbs as $crumbName => $crumbInfo) : ?>
<li class="item <?php /* #escapeNotVerified */ echo $crumbName ?>">
<?php if ($crumbInfo['link']) : ?>
<a href="<?php /* #escapeNotVerified */ echo $crumbInfo['link'] ?>" title="<?php echo $block->escapeHtml($crumbInfo['title']) ?>">
<?php echo $block->escapeHtml($crumbInfo['label']) ?>
</a>
<?php elseif ($crumbInfo['last']) : ?>
<strong><?php echo $block->escapeHtml($crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $block->escapeHtml($crumbInfo['label']) ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
Working fine for me in 2.1

zend framework components DB can't find class Zend_Paginator_Adapter_DbTableSelect

I'm using some Zend libraries outside of the Zend Framework in a small project.
I'm using Zend_Db and Zend_Paginator but when I'm trying to set up the pagination using Zend_Paginator_Adapter_DbTableSelect I get an error that it can't find the class.
Fatal error: Class 'Zend_Paginator_Adapter_DbTableSelect' not found in C:\xampp\htdocs\php_testing\zend\zend_db\index1.php on line 65
Here is my code:
<?
require_once 'Zend/Db.php';
$config=array(
'adapter' => 'PDO_MYSQL',
'hostname' => 'localhost',
'dbname' => 'dm_xxxx',
'username' => 'un',
'password' => 'pw'
);
$db=Zend_Db::factory($config['adapter'], $config);
$select=$db->select()
->from('photocontest__photos', array('*'))
->order('created')
;
require_once 'Zend/Paginator.php';
$currentPageNumber = ($_GET['page'] > 0)?$_GET['page']:'1';
$totalNumberOfItems = 11;
$itemsPerPage = 5;
$pageRange = 10;
$adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
$paginator = new Zend_Paginator($adapter);
$paginator->setCurrentPageNumber($currentPageNumber);
$paginator->setItemCountPerPage($itemsPerPage);
$scrollType = 'Sliding';
$paginator = get_object_vars($paginator->getPages($scrollType));
foreach($paginator AS $item){
echo $item->title.'<br>';
}
?>
thanks
######### UPDATE EDIT ##########
<?
$config=array(
'adapter' => 'PDO_MYSQL',
'hostname' => 'localhost',
'dbname' => 'dm_xxxx',
'username' => 'un',
'password' => 'pw'
);
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
$db=Zend_Db::factory($config['adapter'], $config);
$table = new Photos(array('db' => $db));
$select = $table->select();
$select->setIntegrityCheck(false)
->from('photocontest__photos', array('*'))
->order('created')
;
$currentPageNumber = ($_GET['page'] > 0)?$_GET['page']:'1';
$itemsPerPage = 6;
$adapter = new Zend_Paginator_Adapter_DbTableSelect($select); //Setup the adapter object
$paginator = new Zend_Paginator($adapter); //Setup the actual paginator object
$paginator->setCurrentPageNumber($currentPageNumber);
$paginator->setItemCountPerPage($itemsPerPage); // items pre page
$scrollType = 'Sliding'; //change this to 'All', 'Elastic', 'Sliding' or 'Jumping' to test all scrolling types
Zend_Paginator::setDefaultScrollingStyle('Sliding'); // Sliding or Elastic
//Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
$paginatorControl = get_object_vars($paginator->getPages($scrollType)); //and that's it! we can now use the $paginator variable as we want
?>
<h1>Zend_Paginator Demo</h1>
<ul id="items">
<?php foreach($paginator AS $item): ?>
<li><?php echo $item->title; ?></li>
<?php endforeach ?>
</ul>
<div id="paginator">
<p>Showing <strong><?php echo $paginatorControl['firstItemNumber'] ?> to <?php echo $paginatorControl['lastItemNumber'] ?></strong> out of <strong><?php echo $paginatorControl['totalItemCount'] ?></strong> items</p>
<?php if($paginatorControl['previous']): ?>
« Prev
<?php else: ?>
<span>« Prev</span>
<?php endif ?>
<?php if($paginatorControl['firstPageInRange'] > $paginatorControl['first']): ?>
<?php echo $paginatorControl['first'] ?>
<span>...</span>
<?php endif ?>
<?php foreach($paginatorControl['pagesInRange'] as $page): ?>
<?php if($page == $paginatorControl['current']): ?>
<span><?php echo $page ?></span>
<?php else: ?>
<?php echo $page ?>
<?php endif ?>
<?php endforeach ?>
<?php if($paginatorControl['lastPageInRange'] < $paginatorControl['last']): ?>
<span>...</span>
<?php echo $paginatorControl['last'] ?>
<?php endif ?>
<?php if($paginatorControl['next']): ?>
Next »
<?php else: ?>
<span>Next »</span>
<?php endif ?>
</div>
Edited: I dont think my frirst solution will help you unless you can live without Zend_Paginator_Adapter_DbTableSelect. But looking at your code have you tried including directely DbTableSelect.php?
Try using ::factory.
$paginator = Zend_Paginator::factory($adapter);
$paginator->setCurrentPageNumber($currentPageNumber);
$paginator->setItemCountPerPage($itemsPerPage);
$scrollType = 'Sliding';
$paginator = get_object_vars($paginator->getPages($scrollType));
<?
$config=array(
'adapter' => 'PDO_MYSQL',
'hostname' => 'localhost',
'dbname' => 'dm_xxxx',
'username' => 'un',
'password' => 'pw'
);
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
$db=Zend_Db::factory($config['adapter'], $config);
$table = new Photos(array('db' => $db));
$select = $table->select();
$select->setIntegrityCheck(false)
->from('photocontest__photos', array('*'))
->order('created')
;
$currentPageNumber = ($_GET['page'] > 0)?$_GET['page']:'1';
$itemsPerPage = 6;
$adapter = new Zend_Paginator_Adapter_DbTableSelect($select); //Setup the adapter object
$paginator = new Zend_Paginator($adapter); //Setup the actual paginator object
$paginator->setCurrentPageNumber($currentPageNumber);
$paginator->setItemCountPerPage($itemsPerPage); // items pre page
$scrollType = 'Sliding'; //change this to 'All', 'Elastic', 'Sliding' or 'Jumping' to test all scrolling types
Zend_Paginator::setDefaultScrollingStyle('Sliding'); // Sliding or Elastic
//Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
$paginatorControl = get_object_vars($paginator->getPages($scrollType)); //and that's it! we can now use the $paginator variable as we want
?>
<h1>Zend_Paginator Demo</h1>
<ul id="items">
<?php foreach($paginator AS $item): ?>
<li><?php echo $item->title; ?></li>
<?php endforeach ?>
</ul>
<div id="paginator">
<p>Showing <strong><?php echo $paginatorControl['firstItemNumber'] ?> to <?php echo $paginatorControl['lastItemNumber'] ?></strong> out of <strong><?php echo $paginatorControl['totalItemCount'] ?></strong> items</p>
<?php if($paginatorControl['previous']): ?>
« Prev
<?php else: ?>
<span>« Prev</span>
<?php endif ?>
<?php if($paginatorControl['firstPageInRange'] > $paginatorControl['first']): ?>
<?php echo $paginatorControl['first'] ?>
<span>...</span>
<?php endif ?>
<?php foreach($paginatorControl['pagesInRange'] as $page): ?>
<?php if($page == $paginatorControl['current']): ?>
<span><?php echo $page ?></span>
<?php else: ?>
<?php echo $page ?>
<?php endif ?>
<?php endforeach ?>
<?php if($paginatorControl['lastPageInRange'] < $paginatorControl['last']): ?>
<span>...</span>
<?php echo $paginatorControl['last'] ?>
<?php endif ?>
<?php if($paginatorControl['next']): ?>
Next »
<?php else: ?>
<span>Next »</span>
<?php endif ?>
</div>