doubingling4706 2014-01-17 15:05
浏览 32
已采纳

适用于Zend的Site Wide Class,可用于操作,控制器和视图?

How can you create a site wide function for getting a role or region based on an id. Also things like returning a specific colour based on a calculation of (actual/target), in a view. I want to use it in a view and action.

I have tried, creating a class and setting it up in library:

class Colouring 
{
    /*
     * Array of the class for specifically the GEP portal theme
     */
    private $colours_class = array( 0 => 'color-grey',
                                1 => 'color-grey',
                                2 => 'color-orange',
                                3 => 'color-blue',
                                4 => 'color-green'
                            );

    /*
     * Returns colour based on actual and target
     */
    private static function getColour($actual, $target) 
    {
        ...return someValue

        }
}

Path: Zend_Site/library/

I get the error:

Fatal error: Class 'Colouring' not found in

So then I thought Maybe a View_Helper is what I needed:

So I changed path to: My/View/Helper/Colouring.php and Class to: My_View_Helper_Colouring added this to config.ini: resources.view.helperPath.My_View_Helper_ = "My/View/Helper/"

I use:

$viewHelperObj = $this->view->getHelper('Colouring');
$viewHelperObj->getColour($this->value, $this->divisor);

Gives: Fatal error: Call to a member function getHelper() on a non-object

I tried also:

$this->getColour($this->value, $this->divisor);

Which Gives:

Plugin by name 'GetColour' was not found in the registry

So not really getting the idea of the correct practice to use to add static methods for things that are site wide, or even jsut a site wide class and the way to register. Would I use Plugins, View helpers, Action helpers or just striaght up classes.

I am using Zend 1.

  • 写回答

1条回答 默认 最新

  • dtotwai720621 2014-01-17 16:33
    关注

    first of all you have to rename the method: getColour() to Colouring() and make it public. Then try to call it from view like this:

    echo $this->Colouring('biz', 'bazz');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度