I'm working on restructuring my Zend 1.12 project. I have a couple of view helpers:
I put them in /application/views/helpers
Class names are
As I understand if you have Zend_View_Helper prefix you don't need to add any configs to application.ini
Now, when I try to load any page (even those which don't use helpers) I receive error:
Message: Zend_Session::start() - /otms/vendor/zendframework/zendframework1/library/Zend/Loader.php(Line:134): Error #2 include_once(): Failed opening 'Zend/View/Helper/OutputComplexForm.php' for inclusion (include_path='/otms/application/../library:/otms/application/../library/phpseclib0.3.1:/otms/application/../library/Amazon:/otms/application/../library/USPS:/otms/application/../library/Composer:/otms/library:/otms/vendor/phpseclib/phpseclib/phpseclib:/otms/vendor/zendframework/zendframework1/library:.:/usr/share/php:/usr/share/pear')
Did I miss something?
I've found out that error occurred after calling function
$startedCleanly = session_start(); //line 482
in file /Zend/Session.php. After this call property Zend_Session_Exception::$sessionStartError contains described error message. I still don't see connection between starting session and initialising view helper.
For application-specific classes that you write - stuff that appears inside ./application/*
- should typically not be in the Zend_
pseudo-namespace. Rather, they should be in the appnamespace
, as configured in ./application/config/application.ini
.
The default namespace is 'Application_', so a view-helper called MyHelper
would typically be stored in the file ./application/views/helpers/MyHelper.php
:
class Application_View_Helper_MyHelper extends Zend_View_Helper_Abstract
{
public function myHelper()
{
// do your stuff here
}
}
Note that the class name is upper-camel-case MyHelper
and the method is lower-camelcase myHelper()
.
In your view, you can invoke your view-helper with:
<?php
$output = $this->myHelper();
// Do something with $output
With these conventions on namespace, class name, and file location/name, and invocation syntax, the View's plugin loader should be able find, load, and execute your view-helper method.