Zend Notes: Grabbing a resource from the registry via a view helper

Helper (application/views/helpers):

class Zend_View_Helper_ImageUrlHelper extends Zend_View_Helper_Abstract {
/**
* Helper to grab the path to the images directory
* @param String $imageName
* @param String $imageSize, var for possibly different size requests
*/

public function ImageUrlHelper($imageName, $imageSize) {
$config = Zend_Registry::get(‘config’);
$path = $config-> urlpaths-> productImages;
return $path . ‘/products_’ . $imageSize . ‘/’ . $imageName;
}
}

application.ini (application/configs):

urlpaths.productImages = “/path/images/product_images”

from a view (application/views/scripts/controllerName/viewName.phtml):

<?php $imgSrc = $this-> ProductImageHelper($this-> products[$i][‘products_image’], ‘100’); ?>

<img border=”0″  src=”<?php echo $imgSrc; ?>” />

Comments are closed.