繁体   English   中英

可以在操作,控制器和视图中使用的Zend站点级类吗?

[英]Site Wide Class for Zend that can be used in actions, controllers and views?

如何创建站点范围的功能,以根据ID获得角色或区域。 另外,在视图中还可以根据(实际/目标)的计算返回特定的颜色。 我想在视图和动作中使用它。

我已经尝试过,创建一个类并在库中进行设置:

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

        }
}

路径: Zend_Site/library/

我得到错误:

Fatal error: Class 'Colouring' not found in

因此,我以为也许需要View_Helper:

因此,我将路径更改为: My/View/Helper/Colouring.php ,将类更改为: My_View_Helper_Colouring将其添加到config.ini: resources.view.helperPath.My_View_Helper_ = "My/View/Helper/"

我用:

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

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

我也尝试过:

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

这使:

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

因此,并没有真正获得用于在站点范围内甚至为站点范围内的类和注册方式添加静态方法的正确方法的想法。 我会使用插件,View帮助器,Action帮助器还是只是上课。

我正在使用Zend 1。

首先,您必须将方法重命名: getColour() to Colouring() getColour() to Colouring()并将其公开。 然后尝试从这样的视图调用它:

echo $this->Colouring('biz', 'bazz');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM