9.4 Начало работы с Zend_Paginator. Собираем все воедино

Zend, “Getting Started with Zend_Paginator. Putting it all Together”, public translation into Russian from English More about this translation.

See also 44 similar translations

Translate into another language.

Participants

antdmi339 points
SilverBaby8 points
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next
1 2

Getting Started with Zend_Paginator. Putting it all Together

9.4 Начало работы с Zend_Paginator. Собираем все воедино

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

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.

Вы увидели как создается объект Paginator, как выводятся элементы на текущей странице и как как вывести элементы навигации для перехода по страницам. В этом разделе вы увидите как Paginator вписывается в остальное MVC приложение.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

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.

В следующих примерах мы будем игнорировать рекомендацию использовать слои (Service Layer) что бы сохранить примеры легкими и простыми для понимания. Как только вы познакомитесь с использованием слоев (Service Layer), вы должны легко понять как Paginator может вписаться в это замечательную практику.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

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.

Начнем с контроллера. Пример приложения простой, и мы просто будем выводить все в IndexController и IndexAction. Опять же, это только для демонстрации. В реальном приложении не стоит использовать контроллеры таким образом.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  01. class IndexController extends Zend_Controller_Action

01. class IndexController extends Zend_Controller_Action

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  02. {

02. {

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  03.     public function indexAction()

03. public function indexAction()

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  04.     {

04. {

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  05.         // Setup pagination control view script. See the pagation control tutorial page

05. // Назначение скрипта вида для элементов управления постраничной навигации. Смотрите страницу руководства по элементам управления постраничной навигации (pagination control)

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  06.         // for more information about this view script.

06. //для получения дополнительной информации об этом скрипте вида.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  07.         Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');

07. Zend_View_Helper_PaginationControl::setDefaultViewPartial('controls.phtml');

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  08.  

08.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  09.         // Fetch an already instantiated database connection from the registry

09. // Выбрать уже созданное подключение к базе данных из регистра

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  10.         $db = Zend_Registry::get('db');

10. $db = Zend_Registry::get('db');

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  11.  

11.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  12.         // Create a select object which fetches blog posts, sorted decending by date of creation

12. // Создать объект выборки (select), который выберет записи блога и отсортирует их по дате создания

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  13.         $select = $db->select()->from('posts')->sort('date_created DESC');

13. $select = $db->select()->from('posts')->sort('date_created DESC');

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  14.  

14.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  15.         // Create a Paginator for the blog posts query

15. // Создать Paginator для запроса записей блога

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  16.         $paginator = Zend_Paginator::factory($select);

16. $paginator = Zend_Paginator::factory($select);

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  17.  

17.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

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

18. // Чтение номера текущей страницы из запроса. По умолчанию 1, если номер страницы явно не передан.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  19.         $paginator->setCurrentPageNumber($this->_getParam('page', 1));

19. $paginator->setCurrentPageNumber($this->_getParam('page', 1));

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  20.  

20.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  21.         // Assign the Paginator object to the view

21. // Передать в вид объект Paginator

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  22.         $this->view->paginator = $paginator;

22. $this->view->paginator = $paginator;

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  23.     }

23. }

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

  24. }

24. }

History of edits (Latest: antdmi 4 months, 3 weeks ago) §

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.

Далее скрипт вида index.phtml, скрипт вида для IndexController indexAction. Скрипт вида может быть простым. Мы предполагаем что используется ScrollingStyle по умолчанию.

History of edits (Latest: antdmi 4 months, 3 weeks ago) §
Pages: ← previous Ctrl next
1 2