Class not found in Joomla 4 when using JDate inside a function

by webchun   Last Updated May 07, 2019 00:10 AM

In my last question I tried to modify mod_latest_articles module, and added myCustomFunction to ArticlesLatestHelper.php like this :

/**
 * @package     Joomla.Site
 * @subpackage  mod_articles_latest
 *
 * @copyright   Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Module\ArticlesLatest\Site\Helper;

defined('_JEXEC') or die;

use Joomla\CMS\Access\Access;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Site\Model\ArticlesModel;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;

\JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php');

/**
 * Helper for mod_articles_latest
 *
 * @since  1.6
 */
abstract class ArticlesLatestHelper
{
    /**
     * Retrieve a list of article
     *
     * @param   Registry       $params  The module parameters.
     * @param   ArticlesModel  $model   The model.
     *
     * @return  mixed
     *
     * @since   1.6
     */
    public static function getList(Registry $params, ArticlesModel $model)
    { // this is the built-in function ... }


    public static function myCustomFunction($created_date)
    {
        $date = new JDate($created_date);
        echo $date->format('l, d F Y H:i', false, false);
    }   

I'm able to call the function from the default.php by using @Zollie's solution, but now I got this error message when using JDate inside my function

Error: Class 'Joomla\Module\ArticlesLatest\Site\Helper\JDate' not found: Class 'Joomla\Module\ArticlesLatest\Site\Helper\JDate' not found

Can anybody tell me, what am I doing wrong in here now? Thanks!



Related Questions


Updated February 01, 2017 14:04 PM

Updated June 14, 2016 08:04 AM

Updated November 15, 2016 08:04 AM