1
0
Fork 0
mirror of synced 2025-03-28 19:03:50 +03:00

Updated manual pages and changed documentation naming convention (from process to parse) to follow the API

This commit is contained in:
guilhermeblanco 2008-02-21 14:54:55 +00:00
parent 6ea8a47773
commit ec0ebeb195
2 changed files with 65 additions and 7 deletions

View file

@ -409,7 +409,7 @@ class Doctrine_Pager_Layout
/** /**
* _parseTemplate * _parseTemplate
* *
* Process the template of a given page and return the processed template * Parse the template of a given page and return the processed template
* *
* @param array Optional parameters to be applied in template and url mask * @param array Optional parameters to be applied in template and url mask
* @return string * @return string
@ -426,7 +426,7 @@ class Doctrine_Pager_Layout
/** /**
* _parseUrlTemplate * _parseUrlTemplate
* *
* Processes the url mask to return the correct template depending of the options sent. * Parse the url mask to return the correct template depending of the options sent.
* Already process the mask replacements assigned. * Already process the mask replacements assigned.
* *
* @param $options Optional parameters to be applied in template and url mask * @param $options Optional parameters to be applied in template and url mask
@ -453,7 +453,7 @@ class Doctrine_Pager_Layout
/** /**
* _parseUrl * _parseUrl
* *
* Process the url mask of a given page and return the processed url * Parse the mask replacements of a given page
* *
* @param $options Optional parameters to be applied in template and url mask * @param $options Optional parameters to be applied in template and url mask
* @return string * @return string
@ -476,7 +476,7 @@ class Doctrine_Pager_Layout
/** /**
* _parseUrl * _parseUrl
* *
* Process the url mask of a given page and return the processed url * Parse the url mask of a given page and return the processed url
* *
* @param $options Optional parameters to be applied in template and url mask * @param $options Optional parameters to be applied in template and url mask
* @return string * @return string
@ -493,12 +493,12 @@ class Doctrine_Pager_Layout
return strtr($str, $replacements); return strtr($str, $replacements);
} }
/** /**
* _parseMaskReplacements * _parseMaskReplacements
* *
* Process the mask replacements, changing from to-be replaced mask with new masks/values * Parse the mask replacements, changing from to-be replaced mask with new masks/values
* *
* @param $str String to have masks replaced * @param $str String to have masks replaced
* @return string * @return string

View file

@ -19,6 +19,24 @@ $this->cleanMaskReplacements();
// Parses the template and returns the string of a processed page // Parses the template and returns the string of a processed page
$this->processPage($options = array()); // Needs at least page_number offset in $options array $this->processPage($options = array()); // Needs at least page_number offset in $options array
// Protected methods, although very useful
// Parse the template of a given page and return the processed template
$this->_parseTemplate($options = array());
// Parse the url mask to return the correct template depending of the options sent
// Already process the mask replacements assigned
$this->_parseUrlTemplate($options = array());
// Parse the mask replacements of a given page
$this->_parseReplacementsTemplate($options = array());
// Parse the url mask of a given page and return the processed url
$this->_parseUrl($options = array());
// Parse the mask replacements, changing from to-be replaced mask with new masks/values
$this->_parseMaskReplacements($str);
</code> </code>
Now that you have a small tip of useful methods to be used when extending {{Doctrine_Pager_Layout}}, it's time to see our implemented class: Now that you have a small tip of useful methods to be used when extending {{Doctrine_Pager_Layout}}, it's time to see our implemented class:
@ -63,4 +81,44 @@ class PagerLayoutWithArrows extends Doctrine_Pager_Layout
echo $str; echo $str;
} }
} }
</code>
As you may see, I have to manual process the items <<, <, > and >>. I override the **{%page}** mask by setting a raw value to it (raw value is achieved by setting the third parameter as true). Then I define the only MUST HAVE information to process the page and call it. The return is the template processed as a string. I do it to any of my custom buttons.
Now supposing a totally different situation. Doctrine is framework agnostic, but many of our users use it together with Symfony. {{Doctrine_Pager}} and subclasses are 100% compatible with Symfony, but {{Doctrine_Pager_Layout}} needs some tweaks to get it working with Symfony's {{link_to}} helper function. To allow this usage with {{Doctrine_Pager_Layout}}, you have to extend it and add your custom processor over it. For example purpose (it works in Symfony), I used **{link_to}...{/link_to}** as a template processor to do this job. Here is the extended class and usage in Symfony:
<code type="php">
// CLASS:
class sfDoctrinePagerLayout extends Doctrine_Pager_Layout
{
public function __construct($pager, $pagerRange, $urlMask)
{
sfLoader::loadHelpers(array('Url', 'Tag'));
parent::__construct($pager, $pagerRange, $urlMask);
}
protected function _parseTemplate($options = array())
{
$str = parent::_parseTemplate($options);
return preg_replace(
'/\{link_to\}(.*?)\{\/link_to\}/', link_to('$1', $this->_parseUrl($options)), $str
);
}
}
// USAGE:
$pager_layout = new sfDoctrinePagerLayout(
$pager,
new Doctrine_Pager_Range_Sliding(array('chunk' => 5)),
'@hostHistoryList?page={%page_number}'
);
$pager_layout->setTemplate('[{link_to}{%page}{/link_to}]');
</code> </code>