1

I have complex html form with 10 tabs on my site. When user goes to the page with form method getFormAction() is called

 public function getFormAction()
{
    $productId = $this->_getParam('productId');

    if (!empty($productId)) {

        //Get model and populate form 
        //... 
       $form = new Form_OnixProduct2();
       $form->populate($model);

    } else {
        $form = new Form_OnixProduct2();
    }

    $currentFeedFormSession = new Zend_Session_Namespace('currentFeedSession');

    $currentFeedFormSession->form = $form;

    $this->view->form = $form;

}


}

In this action I initialised Zend_Form, save it to the session variable and in the view I will output only one first tab. All other tabs are displayed using ajax requests - with a call to the action outputOnixTabAction

  public function outputOnixTabAction()
{
    $this->_helper->layout->disableLayout();

    $tabName = $this->_getParam('tabName');

    $currentFeedFormSession = new Zend_Session_Namespace('currentFeedSession');

    $this->view->form = $currentFeedFormSession->form;
    $this->view->tabName = $tabName;

}

My problem is that only first tab is displayed. When I make ajax requests for displaying other tabs I receive the following 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 

Though this helper is successfully loaded in the first tab view. Zend_Session::start() start is called in my custom controller plugin - for every request I check user role with the following code:

    $auth = Zend_Auth::getInstance();

    if($auth->hasIdentity()) {
        $userRole = $auth->getIdentity()->user_type;
    } else {
        $userRole = 'guest';
    }

and hasIdentity() function leads to Zend_Session::start(true) command in Zend/Session/Namespace.php file line 143.

If you have any ideas please share with me.

UPD

Here is an autoloader part from my bootstrap:

    protected function _initAutoload()
{

    $loader = new Zend_Application_Module_Autoloader(
        array(
            'namespace' => '',
            'basePath'  => APPLICATION_PATH
        )
    );

    return $loader;
}

UPD 2

Also I've found out that if I rename helper class from

Zend_View_Helper_OutputComplexForm

to

My_View_Helper_OutputComplexForm

and add line

resources.view.helperPath.My_View_Helper = APPLICATION_PATH "/views/helpers"

to application.ini file everything works fine. But I don't get what it's so special in Zend_ prefix?

Tamara
  • 2,910
  • 6
  • 44
  • 73
  • PHP needs to be able to autoload your `OutputComplexForm` class to prevent this error, so the ZF autoloader code needs to run before the session is started. Which event hook does your controller plugin use (preDispatch(), postDispatch() etc.), and where in your application is your autoloading configuration? – Tim Fountain Mar 10 '15 at 23:09
  • @TimFountain my plugin uses preDispatch() function. What about autoloading configuration, I'm not sure what do you mean? In application.ini I have autoloaderNamespaces properties. In bootstrap I initialise object Zend_Application_Module_Autoloader. – Tamara Mar 11 '15 at 18:51
  • Could you edit your question to include the Zend_Application_Module_Autoloader part from your bootstrap? This should work though - are you sure nothing else in your bootstrap might be using the session? – Tim Fountain Mar 11 '15 at 19:22
  • @TimFountain I added bootstrap autoloader part, please see update – Tamara Mar 11 '15 at 20:25
  • That looks okay. I'm still not quite sure what's happening here, but if using your own namespace fixes it, I'd do that. It's best practice to use your own namespace anyway, the Zend namespace is only intended for ZF classes. – Tim Fountain Mar 11 '15 at 23:20
  • @TimFountain Thanks for the reply. Now I'm just wondering what is so special about Zend_ prefix? Why application try to load this helper during checking user authentication information... – Tamara Mar 12 '15 at 14:10

0 Answers0