We’re rewarding the question askers & reputations are being recalculated! Read more.
7

The global variable $mainframe was remove in Joomla 1.6 and therefore will not work from that version onwards. global $mainframe should be replaced with $mainframe = JFactory::getApplication(); but most people tend to use $app instead. So you code should be like this: $app = JFactory::getApplication(); $app->getSession(); Hope this helps


7

JHtml is normally used in extensions as it's means overrides can be performed which is a really good feature if you're a developer. It also extends $document->... by adding some additional functionality. Here is an example: /js /script.js /script.min.js When using JHtml, the minified version of the script will be loaded to reduce page loading ...


6

In Addition to the others, the single biggest benefit I have found is all CSS / JSS files are in the same array at 1 time. This may not sound like a benefit, but a snippet from another example <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css"> Later on when you want to change system.css, you will ...


5

Joomla provides its own API from their Factory we can call it as JFactory. There is no harm of using: <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css"> over: $document = JFactory::getDocument(); $document->addStyleSheet($url); However, if you are including your stylesheets with above method, ...


4

I am making a guess here, as I can't really test this right now and I am not entirely sure I understood what you want correctly, but this should be in the correct general direction. define( '_JEXEC', 1 ); define( 'JPATH_BASE', $_SERVER["DOCUMENT_ROOT"]); require_once ( JPATH_BASE '/includes/defines.php' ); require_once ( JPATH_BASE '/includes/framework.php'...


4

You should use loadColumn instead of loadResult. loadResult is used when you want to get only 1 value from the query (and is typically used when the query returns just one value), loadColumn is used to return a whole column in an array. See Joomla's official documentation on selecting data from a database.


4

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.0'); JFactory is indeed deprecated. You can rewrite // JFactory is deprecated $db = JFactory::getDbo(); to // Put at the top of your file use Joomla\CMS\...


3

Tags - Similar module uses HAVING clause to achieve this. $query->having('COUNT(' . $db->quoteName('tags.tag_id') . ') = ' . count($tags)); But I'm not sure if this is the best possible solution. It could be rather slow because WHERE IN selects all rows matching any tag and HAVING filters only after the rows have been selected.


3

If I understand it right. You wan't to get the ID of the current active menu. Theres a great example on this forum: https://forum.joomla.org/viewtopic.php?t=642224 Here's the code part: // get application $app = JFactory::getApplication(); // get menu $menu = $app->getMenu(); // get active menu id $activeId = $menu->getActive()->id; // ...


3

After some digging I found this code. Most pages I visited are using outdated code, here is the one that worked for me. $doc = JFactory::getDocument(); $renderer = $doc->loadRenderer('modules'); $position = 'moduleposition'; $options = array('style' => 'raw'); echo $renderer->render($position, $options, null);


3

JHtml::date() will automatically use your timezone setting. JHtml::date('now', 'Y-m-d H:i:s'); See the answer here


3

As for ressources about $mainframe: http://docs.joomla.org/J2.5:What's_new_in_Joomla_2.5 http://docs.joomla.org/Adapting_a_Joomla_1.5_extension_to_Joomla_1.6#Global_Variables_.28.24option_and_.24mainframe.29_are_Gone (Found using Google)


3

Two spaces are hard coded in protected static function createDocument() located inside libraries/joomla/factory.php: $attributes = array( 'charset' => 'utf-8', 'lineend' => 'unix', 'tab' => ' ', 'language' => $lang->getTag(), 'direction' => $lang->isRTL() ? 'rtl' : 'ltr', 'mediaversion' =&...


2

If you read the method documentation, it is doing exactly what its supposed to. Which is return the system default for the number of spaces a keyboard tab event contains. Below is the method as taken from JDocument class: /** * Returns a string containing the unit for indenting HTML * * @return string * * @since 11.1 */ public function _getTab() ...


2

I use the default Joomla multilingual management, no falang, no third-party plugin. Same problem, and I spent 1 hour to find the solution. The key is, don't try to use JFactory::getLanguage(). Instead of that, use JFactory::getSession() and retrieve the result like this: $session = JFactory::getSession(); $lang_obj = $session->get('...


2

You can simply do this by using a core plugin... //Will obtain user object - what the question author needed. $user = JFactory::getUser($uid); //Will authorize you as this user. JPluginHelper::importPlugin('user'); $options = array(); $options['action'] = 'core.login.site'; $response->username = $user->username; $result = $app->triggerEvent('...


2

First of all, you are trying to add code without following Joomla! practices. Then, it is going to be difficult to achieve what your are looking for. For instance, Javascript code is generally located in /media folder. Also, a PHP file without "defined('_JEXEC') or die();" is a bad idea, not following the general security rule to prevent direct access to ...


2

You can set the database driver, just not with any simple function (that I know of), such as setDbo. If you look at the Joomla Database Framework package: use Joomla\Database; class MyApplication extends AbstractApplication { protected $db; protected function initialise() { // Make the database driver. $dbFactory = new ...


2

If you dumped the $_POST in your helper's ajax method you would see that those empty arrays don't hit the server. Joomla's input object is entirely dependent on retrieving the values from $_POST. JQuery ajax doesn't pass empty arrays, see this for example further reading: https://stackoverflow.com/questions/9397669/jquery-ajax-jsonp-how-to-actually-send-an-...


2

Your comment led me to doubt my belief that getDbo() is alive and well. I have tested my below techniques on Joomla3.9.5 and there are no problems. Original answer... Based on this documentation: https://api.joomla.org/cms-3/classes/Joomla.CMS.Factory.html#method_getDbo Returns the global \JDatabaseDriver object, only creating it if it doesn't already ...


1

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 3.9. \Joomla\CMS\Factory::getContainer() doesn't exist in 3.9 as it was only added in 4.0. The code you were looking at is from 4.0, not from 3.9.5. In ...


1

I took the time to set up my own test data and Sharky is correct (+1 to Sharky) about implementing a HAVING clause. $tag_ids = $params->get("tags"); $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select("id, catid, name, alias, image, email_to, published, user_id") ->select(" GROUP_CONCAT(tags.tag_id) AS tag_ids") ->from(...


1

I looked for JFactory instead of looking for getMailer or factory.php in the class conversion chart mentioned in the answer linked in the question and solved this problem myself: $mail = \joomla\CMS\factory::getMailer(); Require is not... required anymore.


1

You haven't included the JFactory so to use Joomla's Database Class. After requiring the framework add: require_once( JPATH_BASE .'/libraries/joomla/factory.php' ); The following are not part of Joomla 3 version - it's normal that you don't see such files. How did they reach to your code? //The following two files do not exist in my Joomla installation, ...


1

To get your db prefix, you need to create object of Jconfig class(configuration file). Let us suppose you are creating a file connectivity.php and place it root. And the code in that file would be : require_once ('configuration.php' ); $var_cls = new JConfig(); $connlink = mysql_connect($var_cls->host, $var_cls->user, $var_cls->password) ...


1

If you simply want to get the ID's and email's of all users that belong to a specific group, you can do the following: $group_id = 8; $usersByGroup = JAccess::getUsersByGroup($group_id); foreach ($usersByGroup as $id) { $user = JFactory::getUser($id); echo $id; echo $user->email; } Of course, change 8 to the ID of the group you wish ...


1

Unfortunately Joomla 3 does not seem to support language initialization in external scripts. I therefore had to construct an alternative solution, which might be of help to others wanting to code external scripts such as APPs and API´s for Joomla 3 with multilanguage support using Joomla´s override language files. Here is what I did. I transferred the ...


1

Long story short, the client had several components similarly named and I wasn't aware that was happening. I was calling against the wrong database. Thank you for the answer, and everybody was correct. I knew somehow something was "off"!


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