code_junkie

How Can I Write Zend Framework URLs That Have Anchor Tags In The Body?

Nov 13th, 2011
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <?= $this->url(array(
  2. 'controller'=>'my.controller',
  3. 'action'=>'my.action',
  4. 'anchor'=>'#myanchor'
  5. ));
  6.  
  7. class My_View_Helper_Url extends Zend_View_Helper_Url
  8. {
  9. public function url(array $urlOptions = array(), $name = null, $reset = false, $encode = true)
  10. {
  11. if (isset($urlOptions['anchor']) && !empty($urlOptions['anchor']))
  12. {
  13. $anchor = $urlOptions['anchor'];
  14. unset($urlOptions['anchor']);
  15. }
  16. else
  17. {
  18. $anchor = '';
  19. }
  20.  
  21. return parent::url($urlOptions, $name, $reset, $encode).$anchor;
  22. }
  23. }
  24.  
  25. <?= $this->url(array(
  26. 'controller'=>'my.controller',
  27. 'action'=>'my.action',
  28. 'anchor'=>'#myanchor'
  29. ));
  30.  
  31. class My_View_Helper_Url extends Zend_View_Helper_Url
  32. {
  33. public function url(array $urlOptions = array(), $name = null,
  34. $reset = false, $encode = true,
  35. $fragment_id = null)
  36. {
  37. $uri = parent::url($urlOptions, $name, $reset, $encode);
  38.  
  39. if(!is_null($fragment_id)) {
  40. $uri .= "#$fragment_id";
  41. }
  42.  
  43. return $uri;
  44. }
  45. }
Add Comment
Please, Sign In to add comment