Advertisement

List of users in PHP - upgrade from Joomla 4 to 5 Topic is solved

For Joomla! 5.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
alanyeom
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sun Mar 23, 2025 7:47 am

List of users in PHP - upgrade from Joomla 4 to 5

Post by alanyeom » Sun Mar 23, 2025 8:06 am

Hi, in Joomla 4 I used the following code to generate a list of users that I then processed in a foreach() loop:

$config =& JFactory::getConfig();

$db =& JFactory::getDBO();
$query = "SELECT * FROM #__users" ;
$db->setQuery($query);
$obj = $db->loadObjectList();

foreach ($obj as $u) {

It no longer works in Joomla 5, and the Joomla manual doesn't help me with this step, only with user handling once I am inside the foreach() loop. How do I do this in Joomla 5?

Advertisement
User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25448
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: List of users in PHP - upgrade from Joomla 4 to 5

Post by pe7er » Sun Mar 23, 2025 10:21 am

Welcome to Joomla forum!

If you haven't seen the new Joomla manual yet, it has a lot of info about Joomla 5 code:
https://manual.joomla.org/docs/next/

You can rewrite the code using name spacing:

Code: Select all

use Joomla\CMS\Factory;

$config = Factory::getConfig();

$db = Factory::getContainer()->get('DatabaseDriver');
$query->select('*')->from($db->quoteName('#__users'));
$db->setQuery($query);
$obj = $db->loadObjectList();

foreach ($obj as $u) {
Kind Regards,
Peter Martin, Global Moderator + Joomla 5.2 Release Manager
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

alanyeom
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sun Mar 23, 2025 7:47 am

Re: List of users in PHP - upgrade from Joomla 4 to 5

Post by alanyeom » Sun Mar 23, 2025 11:40 am

Thanks, that worked fine after I declared the $query object. Consider the question answered!

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 25448
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: List of users in PHP - upgrade from Joomla 4 to 5

Post by pe7er » Sun Mar 23, 2025 12:59 pm

You're welcome! Great!
Kind Regards,
Peter Martin, Global Moderator + Joomla 5.2 Release Manager
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

Advertisement

Post Reply

Return to “Joomla! 5.x Coding”