10.04.2018 Views

Doctrine_manual-1-2-en

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 26: Utilities 344<br />

Listing<br />

26-11<br />

Listing<br />

26-12<br />

// Retrieves the range around the curr<strong>en</strong>t page<br />

// In our example, we are using sliding style and we are at page 1<br />

$pages = $pager_range->rangeAroundPage();<br />

// Outputs: [1][2][3][4][5]<br />

echo '['. implode('][', $pages) .']';<br />

If you build your <strong>Doctrine</strong>_Pager inside the range object, the API gives you <strong>en</strong>ough power<br />

to retrieve information related to <strong>Doctrine</strong>_Pager_Range subclass instance:<br />

// Return the Pager associated to this Pager_Range<br />

$pager_range->getPager();<br />

// Defines a new <strong>Doctrine</strong>_Pager (automatically call _initialize protected<br />

method)<br />

$pager_range->setPager($pager);<br />

// Return the options assigned to the curr<strong>en</strong>t Pager_Range<br />

$pager_range->getOptions();<br />

// Returns the custom <strong>Doctrine</strong>_Pager_Range implem<strong>en</strong>tation offset option<br />

$pager_range->getOption($option);<br />

// Check if a giv<strong>en</strong> page is in the range<br />

$pager_range->isInRange($page);<br />

// Return the range around the curr<strong>en</strong>t page (obtained from <strong>Doctrine</strong>_Pager<br />

// associated to the $pager_range instance)<br />

$pager_range->rangeAroundPage();<br />

Advanced layouts with pager<br />

Until now, we learned how to create paginations and how to retrieve ranges around the<br />

curr<strong>en</strong>t page. To abstract the business logic involving the page links g<strong>en</strong>eration, there is a<br />

powerful compon<strong>en</strong>t called <strong>Doctrine</strong>_Pager_Layout. The main idea of this compon<strong>en</strong>t is to<br />

abstract php logic and only leave HTML to be defined by <strong>Doctrine</strong> developer.<br />

<strong>Doctrine</strong>_Pager_Layout accepts 3 obrigatory argum<strong>en</strong>ts: a <strong>Doctrine</strong>_Pager instance, a<br />

<strong>Doctrine</strong>_Pager_Range subclass instance and a string which is the URL to be assigned as<br />

{%url} mask in templates. As you may see, there are two types of "variables" in<br />

<strong>Doctrine</strong>_Pager_Layout:<br />

Mask<br />

A piece of string that is defined inside template as replacem<strong>en</strong>ts. They are defined as<br />

{%mask_name} and are replaced by what you define in options or what is defined internally<br />

by <strong>Doctrine</strong>_Pager_Layout compon<strong>en</strong>t. Curr<strong>en</strong>tly, these are the internal masks available:<br />

• {%page} Holds the page number, exactly as page_number, but can be overwritable<br />

by addMaskReplacem<strong>en</strong>t() to behavior like another mask or value<br />

• {%page_number} Stores the curr<strong>en</strong>t page number, but cannot be overwritable<br />

• {%url} Available only in setTemplate() and setSelectedTemplate() methods.<br />

Holds the processed URL, which was defined in constructor<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!