I am trying to create a utility class that will hold a lot of special formating functions
that I need all through my application. I did a search and found a lot of yii v1 topics,
but they did not work right.
Here is what I came up with, but it is not working…
I have a file at basic/components/utility/Datetime.php that contains:
<?php
namespace components\utility;
class Datetime
{
public static function gettime( $datetime )
{
// process time field
return( $time );
}
public static function getdate( $datetime )
{
// process date field...
return( $date );
}
}
In controller I have
use components\utility\Datetime;
Then in a controller action I try calling
$date = Datetime::getdate( $datetime );
and it blows up with
Class 'components\utility\Datetime' not found
The key thing I was missing was how to correctly specify the namespace, and getting all the capitalization correct.
To create additional utility class files, just duplicate the Datetime file and change all references to Datetime to the new classname you are using. Be sure to keep the capitalization the same.