Utility class structure, include, use and namespaces
Permalink
I want to write a utility class with a bunch of static methods and make that class available to my block controllers of a package.
Where do I store the utility class file in a package ?
How do I namespace the utility class ?
How do I include and use the utility class in my controllers ?
Sorry if some of this is basic PHP, I have a Java background and I am fairly new to PHP.
Thanks,
Warren Bell
Where do I store the utility class file in a package ?
How do I namespace the utility class ?
How do I include and use the utility class in my controllers ?
Sorry if some of this is basic PHP, I have a Java background and I am fairly new to PHP.
Thanks,
Warren Bell
packages/yourpackage/src/Util.php
might work with util.php, but not sure about that
- How do I namespace the utility class ?
namespace Concrete\Package\Yourpackage\Src;
class Util {
public function hello() {
return 'world';
}
- How do I include and use the utility class in my controllers ?
use Concrete\Package\Yourpackage\Src\Util as Util;
...
echo Util::hello();