我的Zend Framework应用程序中的autoloader找不到Helper类

时间:2012-04-03 17:35:14

标签: zend-framework helpers

我遇到的问题是,在我的ZF应用程序中无法加载动作助手。错误消息是:

未找到名字Sunshine的行动助手

我的ZF应用程序的布局使用了具有以下结构的模块:

application
   modules
      weather
          controllers
             helpers

我已在位于

的Bootstrap模块中注册了帮助程序
application -> modules -> weather -> Bootstrap.php

这是代码

<?php
class Weather_Bootstrap extends Zend_Application_Module_Bootstrap
{

    protected function _initActionHelperBrokers()
    {
        Zend_Controller_Action_HelperBroker::addPath('controllers/helpers', 'Weather_Controllers_Action_Helper_');
    }
}


<?php
class Weather_Controller_Action_Helper_Sunshine extends Zend_Controller_Action_Helper_Abstract 
{

    public function getSunrise() 
    {
        return "06:00";
    }

}

<?php
class Weather_ForecastsController extends Zend_Controller_Action
{

    protected function getForecasts($date) 
    {
        $sunrise = $this->_helper->Sunshine->getSunrise();
        // tbc
    }

这是什么,我在这里做错了什么?

编辑:正如我所建议的那样,我尝试使用完整路径在bootstrap中添加帮助器,但是我得到了同样的错误。

1 个答案:

答案 0 :(得分:0)

addPath方法需要辅助目录的完整路径。将其更改为:

Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/modules/weather/controllers/helpers', 'Weather_Controllers_Action_Helper_');

或者,您也可以通过application.ini添加路径:

resources.frontController.actionhelperpaths.Weather_Controllers_Action_Helper = APPLICATION_PATH "/modules/weather/controllers/helpers"