2

I am trying to migrating old classes names to the new ones available on classmap.php

However after renaming the classes I am having these errors:

Class 'Text' not found //JText works

Class 'BaseController' not found //JControllerLegacy works

I am new to joomla but for my understanding I only need joomla 3.x, which I am running.

Am I missing some import?

1
  • Welcome to JSE, please take our tour.
    – mickmackusa
    Jul 15 '20 at 1:02
1

You need to specify the namespace before you use them, so for your examples above:

use \Joomla\CMS\Language\Text;
use \Joomla\CMS\MVC\Controller\BaseController;

class YourClass extends BaseController {
    echo Text::_('YOUR_CONSTANT');
}

Otherwise, you can do it like this, which is going to get tedious pretty quick:

class YourClass extends \Joomla\CMS\MVC\Controller\BaseController {
    echo \Joomla\CMS\Language\Text::_('YOUR_CONSTANT');
}
3
  • Appreciate your answer. Why Text needs a namespace import while JText does not? I understand it might be defined at root Joomla level, whoever if that's the case why classmap.php isn't aswell?
    – Exprove
    Jul 15 '20 at 13:04
  • JText is registered in classmap.php which is instantiated by libraries/cms.php - required by /includes/framework.php which is required by index.php - hence you don't need to namespace it in Joomla 3. Text needs namespaced because there is no register in classmap.php for it until Joomla 4+
    – Grant G
    Jul 15 '20 at 17:22
  • My answer in this thread, joomla.stackexchange.com/questions/27977/…, explains how to generate a file that contains all the depreciated class and what Use statement to replace it with. I found it very useful when replacing the J prefix classes. If you are using an IDE then it is even better.
    – Irata
    Jul 15 '20 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.