[Solar-talk] $this->action & images

Paul M Jones pmjones at solarphp.com
Wed May 17 14:31:08 PDT 2006


On May 17, 2006, at 4:20 PM, Jeff Surgeson wrote:

> Trying to use a image in a action link instead of text, this worked  
> in prev
> solar versions but does not seem possible in current version due to  
> forced
> escaping.

Sounds like we need an actionImage() helper.  Try this code for a  
start (save as Solar/View/Helper/ActionImage.php, the comments are  
stripped for email brevity) and let me know if it helps.

<?php
Solar::loadClass('Solar_View_Helper');

class Solar_View_Helper_ActionImage extends Solar_View_Helper {

     protected $_uri = null;

     public function __construct($config)
     {
         // do the real configuration
         parent::__construct($config);

         // get a URI processor
         $this->_uri = Solar::factory('Solar_Uri_Action');
     }

     public function action($spec, $src, $attribs = array())
     {
         if ($spec instanceof Solar_Uri_Action) {
             // already an action uri object
             $href = $spec->fetch();
         } else {
             // build-and-fetch the string as an action spec
             $href = $this->_uri->quick($spec);
         }

         // escape the href itself
         $href = $this->_view->escape($href);

         // get the <img /> tag
         $img = $this->_view->image($src, $attribs);

         // done!
         return "<a href=\"$href\">$img</a>";
     }
}
?>




--

Paul M. Jones  <http://paul-m-jones.com>

Solar: Simple Object Library and Application Repository
for PHP5.   <http://solarphp.com>

Savant: The simple, elegant, and powerful solution for
templates in PHP.   <http://phpsavant.com>




More information about the solar-talk mailing list