9 votes

JFactory::getDbo() deprecated-- what's the replacement?

If you are developing your extension only for Joomla 4.0+, you can replace $db = Factory::getDbo(); with $db = Factory::getContainer()->get('DatabaseDriver');
akfaisel's user avatar
  • 121
8 votes

JFactory::getDbo() deprecated-- what's the replacement?

Joomla 3.9.x has a file public_html/libraries/classmap.php that contains all the old style Class names, and the new replacements. E.g. JLoader::registerAlias('JFactory', '\\Joomla\\CMS\\Factory', '5....
pe7er's user avatar
  • 2,023
6 votes
Accepted

JFactory::getDbo() deprecated-- what's the replacement?

Your issue comes solely from confusion about Joomla! versions. These facts should clear the air: \Joomla\CMS\Factory::getDbo() is deprecated in 4.0 and will be removed in 5.0. It is alive and well in ...
Sharky's user avatar
  • 11.1k
6 votes
Accepted

Joomla extension update 3.x and 4.x

Based on this link that Roland Dalmulder sent me to: https://github.com/joomla/joomla-cms/blob/5fdba4e5ee022517a05ae893d8f7077eaf864bf7/libraries/src/Updater/Adapter/ExtensionAdapter.php#L113 ...
mickmackusa's user avatar
  • 4,791
6 votes
Accepted

Joomla 4 create article programmatically

I rewrote the "Content Uploader" for Joomla 4 because I couldn't reach the developer. I had exactly the same problem as you described in the first example. The reason is that the Workflow ...
Gratia-Mira's user avatar
6 votes

Joomla 4 create article programmatically

This will work. $newapp = JFactory::getApplication(); $mvcFactory = $newapp->bootComponent('com_content')->getMVCFactory(); $articleModel = $mvcFactory->createModel('Article', 'Administrator',...
Na Nguyễn's user avatar
6 votes
Accepted

Change database password?

The correct method is to update database password first, either via your hosting control panel or the command line. Then manually update the password in configuration.php either through the File ...
Snaffle's user avatar
  • 146
5 votes
Accepted

How to use HTMLHelper to add to the document head

1) JHtml is an alias for Joomla\CMS\HTML\HTMLHelper class. You'll have to start using the real class sooner or later because the alias will not exist in Joomla! 5.0. To use the real class you have to ...
Sharky's user avatar
  • 11.1k
5 votes
Accepted

Best Practice: Loading component Styles & Scripts in J4

Both have pros and cons. Web Asset Manager is great if your loading an asset that depends on another one. For example: some jQuery plugin that depends on jQuery Your json file can set jQuery as a ...
Lodder's user avatar
  • 26.9k
5 votes

'getErrorMsg' is deprecated in Joomla 4 and what would be the equivalent

I try to give just a short answer on this. We cannot say that there is an “equivalent” of your code snippet in Joomla 4 since Joomla has been handling errors with using core PHP Exceptions. And your ...
Zollie's user avatar
  • 2,926
5 votes
Accepted

Prefill subform with data rows

You need to put the subform data one array deeper. This is because your subform has multiple attribute which means the data should be represented by multiple rows: $prefillData = array("contacts&...
Sharky's user avatar
  • 11.1k
5 votes
Accepted

Can I delay loading a css file until a user is logged in?

Very interesting and good question in my opinion. For this task I would use the 'joomla_user_state' cookie which is available from your template index.php file. (otherwise you can do this form a ...
Zollie's user avatar
  • 2,926
5 votes
Accepted

How to programatically create a user in Joomla 4.x

Factory::getContainer()->get(UserFactoryInterface::class)->loadUserById(0); Joomla uses this line for creating an empty User object around line 287 in ..\libraries\src\User\User.php // If the $...
Irata's user avatar
  • 3,822
4 votes
Accepted

Get Framework and template params in Joomla 4

define('_JEXEC', 1); define('JPATH_BASE', __DIR__ . '/../../..'); require JPATH_BASE . '/includes/defines.php'; require JPATH_BASE . '/includes/framework.php'; // Boot the DI container. $container = \...
Sharky's user avatar
  • 11.1k
4 votes

Menu Model Item in Joomla 4

To get Menu item in Joomla 4 you can get the Item From the Factory like use Joomla\CMS\Factory; $menu = Factory::getApplication()->getMenu(); $active = $menu->getActive(); getActive() will ...
Pratyush's user avatar
  • 496
4 votes
Accepted

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

I’m answering the question because it is obviously not a Joomla 4 core bug but a mistake in the developer’s coding and the problem would be the same in Joomla 3 too. If you try to use a Joomla core ...
Zollie's user avatar
  • 2,926
4 votes
Accepted

How to use cache calls in Joomla 4

The call method has been marked as removed for Joomla 4.0, as it's simply a wrapper for get(). You don't need to manually store the cache as this is done within the get() method: https://github.com/...
Lodder's user avatar
  • 26.9k
4 votes
Accepted

Joomla4 plugin getBody

According to the documentation, JApplicationWeb seems to be alive and well in Joomla4. since 2.5.0 note As of 4.0 this class will be abstract The getters: JApplicationWeb::getBody() Or ...
mickmackusa's user avatar
  • 4,791
4 votes
Accepted

Update from 3.9.x to 4.x

You need to wait for 3.10.X to become available; as per the documentation, "This guide assumes you are starting on Joomla 3.10.x. If you are on a earlier version make sure you upgrade to Joomla 3....
Grant G's user avatar
  • 714
4 votes

How to Fix PHP Deprecated : Factory::getDocument() is deprecated

Use Joomla\CMS\Application\WebApplication::getDocument(). In your code you're already doing this with $app->getDocument().
Sharky's user avatar
  • 11.1k
4 votes
Accepted

Joomla4: Load a custom stylesheet (admin.css.php) in administration

Solved for Joomla 4! I found this tracker entry which lead me to update the php at the beginning of admin.css.php: <?php define('_JEXEC', 1); define('JPATH_BASE', __DIR__ . '/../../..'); ...
Bold's user avatar
  • 123
4 votes

'JEventDispatcher' is deprecated in Joomla 4 and what is the replacement

The ideal way is to have dependencies injected into your objects. Event dispatcher is registered with the global service container so you can fetch it when registering your component services in ...
Sharky's user avatar
  • 11.1k
4 votes
Accepted

Is Joomla4 API/Web Service ready for production use?

You can download the full API collection here: https://github.com/alexandreelise/j4x-api-collection thanks to Alexandre Elise. This will import directly into Postman which will enable you to use the ...
Eoin's user avatar
  • 1,909
4 votes

Adding ajax call in a module for Joomla 4

To use J4 style or custom naming conventions with AJAX you have to convert the module to new service-based format. At a minimum, service provider (services/provider.php) needs to provide a module ...
Sharky's user avatar
  • 11.1k
4 votes

jQuery scripts not working in Joomla 4 template

Yes, for the most part J4 uses vanilla JavaScript and dependencies like jQuery should be loaded only when needed. If it's needed by your template's script files, you can add it as dependency in your ...
Sharky's user avatar
  • 11.1k
4 votes

Is the following everything one should do to prevent SQL injection?

First, when reading user input you should make sure it's the correct type. The Input/Filter APIs don't handle array/string conversion. So if you're expecting STRING filter to return a string be aware ...
Sharky's user avatar
  • 11.1k
4 votes

JRequest Method in Joomla 4

Use Joomla\Input\Input class. Instance relevant to the current request can be accessed through the application: use Joomla\CMS\Factory; $controller->execute(Factory::getApplication()->getInput()...
Sharky's user avatar
  • 11.1k
4 votes

Joomla 4 API Question

Academic explanation of J! 4 webservices route mapping This is an explanation of how Joomla 4 (hereafter referred to as J! 4) webservices route resolution and method finding works. Disclaimer What ...
Joe Hacobian's user avatar
4 votes
Accepted

How to show list of articles filtered by category and custom field

You can filter on Custom Fields via multiple ways: filtering via JavaScript + CSS. This will load all articles, but can CSS hide (display:none) them using some JavaScript. The articles are still ...
pe7er's user avatar
  • 2,023
4 votes

How to create a (better) development environment for Joomla 4

I've not used Docker so I can't help with that, but I have xdebug set up on my local environment in combination with PHPStorm and that is a big help in enabling me to figure out why something's not ...
Grant Hood's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible