23

Joomla: Accessing User Info - The User Object To get user information for the current user: $user = JFactory::getUser(); It will return the User Object. Here, some of the most common User Object's Properties: id ($user->id) name ($user->name) username ($user->username) groups ($user->groups) email ($user->email). You can check if the ...


23

For Joomla 3.x While the code from the other answer will work, JRequest is deprecated, therefore you should use the following: $jinput = JFactory::getApplication()->input; echo $jinput->get('option'); For example, if you are displaying an Article and use the above code, it will output com_content


14

A more thorough walk through should really be added to the docs wiki IMO, but sharing what I can via mobile now. For 2.5 and 3.x compatibility, you can use JBrowser to do some browser detection. However, this class may not work well with newer browsers or versions. To use it to get the browser: $browser = JBrowser::getInstance()->getBrowser(); For 3....


13

JError has been deprecated in J3.x, in favour of PHP exceptions, as it intermixed 2 different programming concepts: logging and error handling (the logging side has now been implemented as JLog). For your exact case, you can wrap your code in a try / catch block to get the error, as shown in this SO answer: try { ... $db->setQuery($query); $...


13

Answer's ToC 1. Intro for beginners + beginners resources link 2. About Joomla Architecture 3. Joomla Execution Flow - How Joomla Works 4. Supplementary Resources 1. Intro for Beginners Using Joomla for site building is rather simple, as it provides a friendly administration area. In most cases this is all that is needed to know for end-users and ...


12

That code is looking in the article text you need to is in the images call. It is json encoded so you have to decoded it first. $images = json_decode($this->item->images); echo $images->image_intro; Have a look at the com_content/article/default.php template to see some of the other parts of data you can use for images.


11

In a proper MVC structure, only your controller should interface with your request data, in this case JInput, and the dependencies injected into the view and model when instantiated within the controller. With the current CMS structure, all three pieces of the MVC structure are often interfacing with the request data. In models, this is usually done in the ...


10

To get the data of the active (current) menu item, use the following code: $app = JFactory::getApplication(); // Access the Application Object $menu = $app->getMenu(); // Load the JMenuSite Object $active = $menu->getActive(); // Load the Active Menu Item as an stdClass Object The $active is an object of the current menu item. ...


9

In addition to Michael's answer, the JApplicationWebClient Class has a few other useful properties: $client = JFactory::getApplication()->client; $client->browser; // The detected browser used by the web client (returns an integer) $client->browserVersion; // The detected browser version used by the web client. (string) $client->mobile; // ...


9

First of all you need to pass article ID with your request. Then you can use JTable class to update the state: public function onAjaxDeletearticle() { // Get id from the request $id = JFactory::getApplication()->input->getInt('data'); // Get the new instance of #__content table $table = JTable::getInstance('content'); // Load the ...


9

You firstly need to create a helper file, for example: administrator/components/com_helloworld/helpers/helloworld.php and in this file, add the following: class HelloWorldHelper extends JHelperContent { public static function addSubmenu($vName) { JHtmlSidebar::addEntry( 'test', 'index.php?option=com_hellowworld&...


9

For Joomla 2.5 We can check by getting the URL parameters, using the JRequest::getVar() method and check for the option parameter. jimport( 'joomla.environment.request' ); echo JRequest::getVar('option', '') JRequest API Documentation


9

You should use Joomla's JInput class https://docs.joomla.org/Retrieving_request_data_using_JInput e.g. public function add() { // Get Joomla's input object: $input = JFactory::getApplication()->input; // Get the variable $value = $input->get('id'); $session = JFactory::getSession(); $cart = array(); $cart['item'] = array('id' => $...


9

Starting from Joomla 3.6 you can add 'property' attribute using setMetaData $doc = JFactory::getDocument(); $doc->setMetaData('og:image', 'https://cdn.joomla.org/images/Joomla_logo.png', 'property'); Reference : https://github.com/joomla/joomla-cms/pull/10682


9

There are a few options, but I use the jBackend extension. Some positives of jBackend. Nice clean JSON Comes with good boilerplate code to get started Manages API keys API endpoint code transmits and receives data Basically exposes many common CMS functions as API endpoints Has a normal looking Joomla admin UI for managing API keys Documentation is good ...


8

There is a good doc page explaining the differences between Joomla 2.5 and 3.x. http://docs.joomla.org/Potential_backward_compatibility_issues_in_Joomla_3_and_Joomla_Platform_12.2 The only thing to mention is that the legacy classes are only available in Joomla 2.5.5 and higher. But anyone should be on 2.5.19 nowadays anyway :)


8

Instead of JDocumentRenderer you should use JModuleHelper to render modules: foreach($modules as $mod) { echo JModuleHelper::renderModule($mod, $attribs); } See renderModule() method.


8

From my experience: About Joomla framework I tried to build a simple RESTful API for integrated authentication based on Joomla framework. It's fairly complex, quite different than the current Joomla API. Also, current source code can't be copy-pasted, and libraries may return unexpected results (being executed in a different environment). I'm going to wait ...


8

$db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select('a.id, a.name, c.id as parent_id, c.name as parent_name') ->from('#__records as a'); $query->select('b.parent as parentid'); $query->join('LEFT', '#__parents AS b ON b.child = a.id'); $query->join('LEFT', '#__records AS c ON b.parent = c.id'); $db->setQuery($query)...


7

@Lodder is correct. If you want just some basic fields, then you can use Joomla User Profile plugin, which comes with Joomla itself. If you want to create some customized fields, then there are various options available like, Community Builder, JomSocial, EasySocial and other socila networking solution. But if don't want the full community solution then you ...


7

The documentation is stored in our JIssues GitHub repo in Markdown format for easy processing and contributing. To display the docs on site, we use a command line script which scans the folder, parses the Markdown document into HTML via the GitHub API, and the rendering is stored into the database.


7

That will work if isRoot has been set. But, it requires a call to JUser::authorise() having been completed first. This snippet would work at all times: $user = JFactory::getUser(); $isroot = $user->authorise('core.admin');


7

Add this to your view.html.php to add the button to the toolbar: // Get the toolbar object instance $bar = JToolBar::getInstance('toolbar'); JHtml::_('bootstrap.modal', 'collapseModal'); $title = JText::_('JTOOLBAR_BATCH'); // Instantiate a new JLayoutFile instance and render the batch button $layout = new JLayoutFile('joomla.toolbar.batch'); $dhtml = $...


7

Passing the message via the redirect function is deprecated, but both redirect() and enqueueMessage() are still both fine to use on their own. You simply need to use both together, like so: $app = JFactory::getApplication(); $app->enqueueMessage('Redirect to another page was successful', 'success'); $app->redirect(JRoute::_('index.php')); ...


6

JDocument->addScript() has options to defer the loading of the script and/or load it async. See the API doc: http://api.joomla.org/cms-3/classes/JDocumentHTML.html#method_addScript This will allow the browser to load the scripts later in the process, which will help with the pageload time. There is no API to load the scripts at the bottom of the page. If ...


6

Pretty much the same as @ValentinDespa 's answer but i'm just gonna merge the two things together into something that will work in 2.5 and 3.x. This rather than displaying a full page error message just returns false and then inserts an error message into the top of the page. Hope that's what you're after $db = JFactory::getDbo(); $query = $db->getQuery(...


6

com_api is definitely a good way to build REST services for your site if the extension itself is not based on FOF/RAD. However be careful with a few gotchas if you plan to create a separate Joomla instance only for the API Domain specific stuff (Eg: If you are supporting user registration, then the welcome email would include a link to the API subdomain). ...


6

I finally found what seems to be the "correct" way to do this. Even if I used sendHeaders, the additional Content-Type was being added and that got returned as it was added later. I followed through the code and AbstractWebApplication.php sets the headers with this line: // Send the content-type header. $this->setHeader('Content-Type', $this->...


6

You can modify this code from Joomla Docs to fit your needs, depending on what you're trying to achieve: $db = JFactory::getDbo(); $query = $db->getQuery(true); // Fields to update. $fields = array( $db->quoteName('profile_value') . ' = ' . $db->quote('Updating custom message for user 1001.'), $db->quoteName('ordering') . ' = 2' ); // ...


6

This is how Joomla user profile plugins does // Sanitize the date $data['profile']['dob'] = $this->_date; $db = JFactory::getDbo(); $query = $db->getQuery(true) ->delete($db->quoteName('#__user_profiles')) ->where($db->quoteName('user_id') . ' = ' . (int) $userId) ->where($db->...


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