Introducción a Zend Framework

 Aprendiendo Zend Framework


 Referencia de Zend Framework

  • Zend_Gdata
  • Zend_Http
  • Zend_InfoCard
  • Zend_Json
  • Zend_Layout
  • Zend_Ldap
  • Zend_Loader
  • Zend_Locale
  • Zend_Log
  • Zend_Mail
  • Zend_Markup
  • Zend_Measure
  • Zend_Memory
  • Zend_Mime
  • Zend_Navigation
  • Zend_Oauth
  • Zend_OpenId
  • Zend_Paginator
  • Zend_Pdf
  • Zend_ProgressBar
  • Zend_Queue
  • Zend_Reflection
  • Zend_Registry
  • Zend_Rest

  • Zend_Search_Lucene
  • Zend_Serializer
  • Zend_Server
  • Zend_Service
  • Zend_Session
  • Zend_Soap
  • Zend_Tag
  • Zend_Test
  • Zend_Text
  • Zend_TimeSync
  • Zend_Tool
  • Zend_Tool_Framework
  • Zend_Tool_Project
  • Zend_Translate
  • Zend_Uri
  • Zend_Validate
  • Zend_Version
  • Zend_View
  • Zend_Wildfire
  • Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Traducción al 26.9% - Actualizado el 2011-11-16 - Revisión 24249 - Versión ZF 1.11.x

    11.4. Putting it all Together

    You have seen how to create a Paginator object, how to render the items on the current page, and how to render a navigation element to browse through your pages. In this section you will see how Paginator fits in with the rest of your MVC application.

    In the following examples we will ignore the best practice implementation of using a Service Layer to keep the example simple and easier to understand. Once you get familiar with using Service Layers, it should be easy to see how Paginator can fit in with the best practice approach.

    Lets start with the controller. The sample application is simple, and we'll just put everything in the IndexController and the IndexAction. Again, this is for demonstration purposes only. A real application should not use controllers in this manner.

    class IndexController extends Zend_Controller_Action
        public function 
    // Setup pagination control view script. See the pagation control tutorial page
            // for more information about this view script.

    // Fetch an already instantiated database connection from the registry
    $db Zend_Registry::get('db');

    // Create a select object which fetches blog posts, sorted decending by date of creation
    $select $db->select()->from('posts')->sort('date_created DESC');

    // Create a Paginator for the blog posts query
    $paginator Zend_Paginator::factory($select);

    // Read the current page number from the request. Default to 1 if no explicit page number is provided.

    // Assign the Paginator object to the view
    $this->view->paginator $paginator;

    The following view script is the index.phtml view script for the IndexController's indexAction. The view script can be kept simple. We're assuming the use of the default ScrollingStyle.

    // Render each the title of each post for the current page in a list-item
    foreach ($this->paginator as $item) {
    '<li>' $item->title '</li>';
    <?php echo $this->paginator?>

    Now navigate to your project's index and see Paginator in action. What we have discussed in this tutorial is just the tip of the iceberg. The reference manual and API documentation can tell you more about what you can do with Zend_Paginator.

    digg delicious meneame google twitter technorati facebook