I am a newbie to Lithium PHP and know the basics of Lithium. I want to implement my own Utility
functions. I have created the utilities
folder parallel to app\controllers
. This is how my class looks like:
<?php
namespace app\utilities;
class UtilityFunctions {
protected $_items = array(
'a' => 'Apple',
'b' => 'Ball',
'c' => 'Cat'
);
//I get _items as undefined here, blame my poor OOP skills.
public function getItem(alphabet) {
return $this->_items[alphabet];
}
}
?>
I use it in my controller as:
<?php
namespace app\controllers;
use \app\utilities\UtilityFunctions;
class MyController extends \lithium\action\Controller {
public function index() {
$args = func_get_args();
$item = UtilityFunctions::getItem($args[0]);
return compact('item');
}
}
?>
Is this the right way to do it? Does my utility class need to extend something? Or does Lithium provide some other way to achieve this?
Moreover, I am not able to access the protected variable $_items
in my getItems
method. I had the same thing implemented in my controller and it worked fine then.