|
||||
|
I am having this issue of ZF locating where my custom View Helper classes are. The only way my view helpers work is when I include them in the Zend_View_Helper path - which ideally, I don’t want to do.
So I have a plugin folder in my library folder (apps>lib>Addon) In this folder I have my folders as required (View & Helper folders) For the view helper class I have done what is required ( TitleCasing the helper class name, prefixing the class name with the plugin folder path to the view helper folder & camelCasing the helper function name) In my bootstrap included a path to where my view helper folder. And In my view script I made a function call to this helper function but on preview my page just appears blank. It is only displays when I move the view helper class to Zend_View_Helper as mentioned above! I am having similar problems with adding custom plugins too. ZF cant seem to resolve the path in these two cases. I have tried all sorts. I came across this article( Zend_View helpers in include path) and I just want to know if you will recommend the route this guy suggests on solving this and if this behavior of the Zend_View is still true with the v1.5? How can i get Zend_View to see my custom folders?? |
|
|||
|
You need to tell Zend_View where your helpers are, following your example (assuming your library is on drive w:\, for the sake of the example):
Code:
// instantiate the view and save Zend_View object to a variable
$view = new Zend_View();
// add to the helper path
$view->addHelperPath('W:\library\Addon\View\Helper', 'Addon_View_Helper');
$renderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$renderer->setView($view);
|
|
|||
|
Perhaps you can post the code from your index.php here so we can take a look at it. If the helper works when placed in the Zend library that suggests to me that it is not an issue with the naming of the class or its methods, but rather with making it available to Zend_View via the addHelperPath() method.
I assume you have the entire library directory in the PHP include path... |
|
||||
|
Quote:
Indeed i do i will post the code from index.php as well as a snapshot of my folder structure. Thanks |
|
||||
|
Apache httpd.conf include path
Code:
php_value include_path ".;C:/xampp/htdocs/xampp/mainevent/apps/lib;C:/xampp/php/PEAR;C:/xampp/htdocs/xampp/mainevent/apps;C:/xampp/htdocs/xampp/mainevent/apps/modules/admin/views/forms;" Index.php file: Code:
<?php require_once 'Bootstrap.php'; Bootstrap::run(); ?> Bootstrap.php file: Code:
<?php
require_once 'Zend/Loader.php';
require_once 'Zend/Session.php';
class Bootstrap{
public static function run() {
...
self::prepare();
...
}
public static function prepare() {
self::setupController();
self::setupView();
}
public static function setupView() {
$view = new Zend_View;
$prefix = 'Addon_View_Helper';
$config = Zend_Registry::get('config');
$dir = $config->paths->data . '/lib/Addon/View/Helper';// from config file: C:/xampp/htdocs/xampp/mainevent/apps
$view->addHelperPath($dir,$prefix);
$view->setEncoding('UTF-8');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
}
![]() Custom View Helper: Code:
<?php
class Addon_View_Helper_DateFormat {
public function dateFormat($date="") {
$pieces = explode("-",$date,3);
$newDate = $pieces[2] . "/" . $pieces[1] . "/" . $pieces[0];
return $newDate;
}
}
?>
Code:
[development] paths.base = C:/xampp/htdocs/xampp/mainevent paths.data = C:/xampp/htdocs/xampp/mainevent/apps paths.modules.admin = C:/xampp/htdocs/xampp/mainevent/apps/modules/admin paths.templates = C:/xampp/htdocs/xampp/mainevent/templates |
![]() |
| Thread Tools | |
| Display Modes | |
|
|