Reputation: 11098
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.
Upvotes: 0
Views: 48
Reputation: 691
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');
Upvotes: 1