Changeset 3875
- Timestamp:
- 02/21/08 14:54:55 (17 months ago)
- Files:
-
- 4 modified
-
branches/0.10/lib/Doctrine/Pager/Layout.php (modified) (5 diffs)
-
branches/0.10/manual/docs/en/utilities/pagination/customizing-pager-layout.txt (modified) (2 diffs)
-
trunk/lib/Doctrine/Pager/Layout.php (modified) (5 diffs)
-
trunk/manual/docs/en/utilities/pagination/customizing-pager-layout.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.10/lib/Doctrine/Pager/Layout.php
r3874 r3875 410 410 * _parseTemplate 411 411 * 412 * P rocessthe template of a given page and return the processed template412 * Parse the template of a given page and return the processed template 413 413 * 414 414 * @param array Optional parameters to be applied in template and url mask … … 427 427 * _parseUrlTemplate 428 428 * 429 * P rocessesthe url mask to return the correct template depending of the options sent.429 * Parse the url mask to return the correct template depending of the options sent. 430 430 * Already process the mask replacements assigned. 431 431 * … … 454 454 * _parseUrl 455 455 * 456 * P rocess the url mask of a given page and return the processed url456 * Parse the mask replacements of a given page 457 457 * 458 458 * @param $options Optional parameters to be applied in template and url mask … … 477 477 * _parseUrl 478 478 * 479 * P rocessthe url mask of a given page and return the processed url479 * Parse the url mask of a given page and return the processed url 480 480 * 481 481 * @param $options Optional parameters to be applied in template and url mask … … 494 494 return strtr($str, $replacements); 495 495 } 496 497 496 497 498 498 /** 499 499 * _parseMaskReplacements 500 500 * 501 * P rocessthe mask replacements, changing from to-be replaced mask with new masks/values501 * Parse the mask replacements, changing from to-be replaced mask with new masks/values 502 502 * 503 503 * @param $str String to have masks replaced -
branches/0.10/manual/docs/en/utilities/pagination/customizing-pager-layout.txt
r3872 r3875 20 20 // Parses the template and returns the string of a processed page 21 21 $this->processPage($options = array()); // Needs at least page_number offset in $options array 22 23 // Protected methods, although very useful 24 25 // Parse the template of a given page and return the processed template 26 $this->_parseTemplate($options = array()); 27 28 // Parse the url mask to return the correct template depending of the options sent 29 // Already process the mask replacements assigned 30 $this->_parseUrlTemplate($options = array()); 31 32 // Parse the mask replacements of a given page 33 $this->_parseReplacementsTemplate($options = array()); 34 35 // Parse the url mask of a given page and return the processed url 36 $this->_parseUrl($options = array()); 37 38 // Parse the mask replacements, changing from to-be replaced mask with new masks/values 39 $this->_parseMaskReplacements($str); 22 40 </code> 23 41 … … 65 83 } 66 84 </code> 85 86 87 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. 88 89 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: 90 91 <code type="php"> 92 // CLASS: 93 94 class sfDoctrinePagerLayout extends Doctrine_Pager_Layout 95 { 96 public function __construct($pager, $pagerRange, $urlMask) 97 { 98 sfLoader::loadHelpers(array('Url', 'Tag')); 99 parent::__construct($pager, $pagerRange, $urlMask); 100 } 101 102 103 protected function _parseTemplate($options = array()) 104 { 105 $str = parent::_parseTemplate($options); 106 107 return preg_replace( 108 '/\{link_to\}(.*?)\{\/link_to\}/', link_to('$1', $this->_parseUrl($options)), $str 109 ); 110 } 111 } 112 113 114 115 // USAGE: 116 117 $pager_layout = new sfDoctrinePagerLayout( 118 $pager, 119 new Doctrine_Pager_Range_Sliding(array('chunk' => 5)), 120 '@hostHistoryList?page={%page_number}' 121 ); 122 123 $pager_layout->setTemplate('[{link_to}{%page}{/link_to}]'); 124 </code> -
trunk/lib/Doctrine/Pager/Layout.php
r3874 r3875 410 410 * _parseTemplate 411 411 * 412 * P rocessthe template of a given page and return the processed template412 * Parse the template of a given page and return the processed template 413 413 * 414 414 * @param array Optional parameters to be applied in template and url mask … … 427 427 * _parseUrlTemplate 428 428 * 429 * P rocessesthe url mask to return the correct template depending of the options sent.429 * Parse the url mask to return the correct template depending of the options sent. 430 430 * Already process the mask replacements assigned. 431 431 * … … 454 454 * _parseUrl 455 455 * 456 * P rocess the url mask of a given page and return the processed url456 * Parse the mask replacements of a given page 457 457 * 458 458 * @param $options Optional parameters to be applied in template and url mask … … 477 477 * _parseUrl 478 478 * 479 * P rocessthe url mask of a given page and return the processed url479 * Parse the url mask of a given page and return the processed url 480 480 * 481 481 * @param $options Optional parameters to be applied in template and url mask … … 494 494 return strtr($str, $replacements); 495 495 } 496 497 496 497 498 498 /** 499 499 * _parseMaskReplacements 500 500 * 501 * P rocessthe mask replacements, changing from to-be replaced mask with new masks/values501 * Parse the mask replacements, changing from to-be replaced mask with new masks/values 502 502 * 503 503 * @param $str String to have masks replaced -
trunk/manual/docs/en/utilities/pagination/customizing-pager-layout.txt
r3872 r3875 20 20 // Parses the template and returns the string of a processed page 21 21 $this->processPage($options = array()); // Needs at least page_number offset in $options array 22 23 // Protected methods, although very useful 24 25 // Parse the template of a given page and return the processed template 26 $this->_parseTemplate($options = array()); 27 28 // Parse the url mask to return the correct template depending of the options sent 29 // Already process the mask replacements assigned 30 $this->_parseUrlTemplate($options = array()); 31 32 // Parse the mask replacements of a given page 33 $this->_parseReplacementsTemplate($options = array()); 34 35 // Parse the url mask of a given page and return the processed url 36 $this->_parseUrl($options = array()); 37 38 // Parse the mask replacements, changing from to-be replaced mask with new masks/values 39 $this->_parseMaskReplacements($str); 22 40 </code> 23 41 … … 65 83 } 66 84 </code> 85 86 87 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. 88 89 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: 90 91 <code type="php"> 92 // CLASS: 93 94 class sfDoctrinePagerLayout extends Doctrine_Pager_Layout 95 { 96 public function __construct($pager, $pagerRange, $urlMask) 97 { 98 sfLoader::loadHelpers(array('Url', 'Tag')); 99 parent::__construct($pager, $pagerRange, $urlMask); 100 } 101 102 103 protected function _parseTemplate($options = array()) 104 { 105 $str = parent::_parseTemplate($options); 106 107 return preg_replace( 108 '/\{link_to\}(.*?)\{\/link_to\}/', link_to('$1', $this->_parseUrl($options)), $str 109 ); 110 } 111 } 112 113 114 115 // USAGE: 116 117 $pager_layout = new sfDoctrinePagerLayout( 118 $pager, 119 new Doctrine_Pager_Range_Sliding(array('chunk' => 5)), 120 '@hostHistoryList?page={%page_number}' 121 ); 122 123 $pager_layout->setTemplate('[{link_to}{%page}{/link_to}]'); 124 </code>