Hot answers tagged

31

$app = JFactory::getApplication(); $postData = $app->input->post; Is the way to go, you will get a JInput object and can use it like JRequest $var = $postData->get('varname', 'defaultvalue', 'filter'); The filter could be 'int', 'cmd' or many others - the complete list can be found in this function: https://github.com/joomla/joomla-cms/blob/...


29

these codes will determine if current logged in user is super user or not - $user = JFactory::getUser(); $isroot = $user->authorise('core.admin'); that code will check what is mapped to the "Super User" permission in the global configuration and not in only component level. Check it yourself comparing with other ways.


25

There are several steps you can take to increase server side performance. Do note that some of these will not work with most shared hosts. For great performance you usually need more fine grained control. As with any optimizations, you should measure the effect it has on your site's performance. For basic optimizations are tools like PageSpeed and YSlow ...


18

As @DmitryRekun said, a good discussion is here. The key piece to consider in all of this is what type of error do you have? There are two types of errors: Recoverable Unrecoverable. The difference I tend to sum up as follows: Can I still show the page that was requested, even though this error occurred? Yes? - Recoverable No? - Unrecoverable Now that ...


16

Yes, as far as i'm concerned, the way you built the subquery is the one adopted by the majority of joomla's extensions developers. I use that same method on some of my extensions and custom extensions made for clients. There is no "official" way of doing this, but doing it as you showed lets you use the query builder and still retain a good amount of ...


16

You can get the prefix using the following: For Joomla 2.5 use: $app = JFactory::getApplication(); $prefix = $app->getCfg('dbprefix'); For Joomla 3.2 use: $app = JFactory::getApplication(); $prefix = $app->get('dbprefix'); But Joomla documentation recommends that you never modify the prefix. I know some backup software allows you to make a ...


16

In addition to @Bakual's answer, let's assume you a simple form like so: <form name="upload" method="post" enctype="multipart/form-data"> <input type="file" name="file_upload"> </form> To upload the file once the submit button has been pressed, you can use this: $input = JFactory::getApplication()->input; $file = $input->files-...


15

$this->baseurl; is basically the shortcut for JUri::base(). It gets the URL you have specified as the live_site variable in your configuration.php file. If this has no value, then it will use some PHP magic based on a few variables. So, lets run a few tests. Please report the results back: Test 1: <?php echo 'Rule 1: ' . JUri::base() . '\n'; echo '...


15

It's a rather extensive process to do this, but here's a trimmed down version of the code that I generally use. I won't necessarily guarantee that it will run as shown since I ripped out a bunch of internal stuff that we do along the way, but these are the pieces you need to do it. You'll need to look at tables #__categories and #__content to get all the ...


13

Use JRoute for this: rtrim(JUri::base(), '/') . JRoute::_(ContentHelperRoute::getArticleRoute( $article->id, $article->catid )) but you don't need JUri::base() if you don't want to link to a different domain.


13

One BIG thing you can do to improve response times for your site is to update your module settings. Custom modules (using mod_custom) have an option to enable / disable the preparing of content. This allows you to run content plugins on the data content within your custom module. It's powerful when used properly, but it does add additional rendering time to ...


13

Try this, Did you mean to render the module output using a PHP script? In which case, then take a look at this: For older versions < Joomla3.x $document = JFactory::getDocument(); $renderer = $document->loadRenderer('module'); $module = JModuleHelper::getModule('mod_fmDataGrid'); $params = "param1=bruno\n\rparam2=chris"; $module->params =...


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

Here is how I'm managing an errors. View or Controller try { $this->item = $this->get('Item'); } catch (Exception $e) { if ($e->getCode() == 404) { // Not found throw new Exception($e->getMessage(), 404); } // Generic errors JFactory::getApplication()->enqueueMessage(JText::_('...


12

I use this way: // Check for component if (!JComponentHelper::getComponent('<component name>', true)->enabled) { ..... } <component name> - without "com_" prefix


12

The best practice is to create the addToolBar() method inside your View class and then using JToolBarHelper class to create command buttons: protected function addToolBar() { JToolBarHelper::addNew('yourcontroller.add'); JToolBarHelper::editList('yourcontroller.edit'); } So these will call the task/function "add"/"edit" in your specified controller. ...


11

Step 1 Edit “components/com_content/router.php“, then continue on step 2. (You’ll probably have to re-do this step every time you update Joomla.) Step 2 (There are two places need to do this change, one near the top, one in the middle) Replace this: $advanced = $params->get('sef_advanced_link', 0); With this: $advanced = $params->get('...


10

AFAIK there isn't a built in way to do easy subqueries, which is probably a deficiency in the system and should be corrected via PR. However, I see no issue with your example - seems reasonable enough. ~~~ Here's an example in response to @DavidFritsch's comment below. The more that I think about it though, the better I like the more simple approach ...


10

Try this code: $menu = JFactory::getApplication()->getMenu(); $parent = $menu->getItem( $menu->getActive()->parent_id ); $parentname = $parent->title If you need the link $parentlink = JRoute::_( $parent->link . '&Itemid=' . $parent->id );


10

Jloader::import Will include the whole specified file into our script and do some joomla specific naming conventions -> where as JLoader::register Will allows us To Include only needed class from specified packeg file and it also uses php's auto-loader that speeds up the app and save memory


10

To get an array of groups the currently logged in user belong to, you can use the following: $user = JFactory::getUser(); $groups = JAccess::getGroupsByUser($user->id); var_dump($groups); To get the names of these groups, you can run a database query (add after the code above) $user = JFactory::getUser(); $groups = JAccess::getGroupsByUser($user-&...


9

It depends on what .php document you're in - if you're in item.php, or the category-item.php files, the following should work. In the top of the document, add this code: <!-- Call to prepare extra fields --> <?php $extrafields = array(); foreach($this->item->extra_fields as $item) { $extrafields[$item->id] = $item->value; } ?&...


9

At work we try to resolve all PHP warnings, errors and strict standards violations. In situations like this, where the signatures are different, there's no way to resolve it other using two separate, version specific class files. I'm curious though why that's not an option for you? Version specific class files are actually simple to implement, but a bit ...


9

This was used for PHP4 times. From PHP5 onwards objects are assigned by reference, so there is no need to do that explicitly.


9

Instead of using and incrementing $num, replace that with $item->level. echo '<ul class="nav-child unstyled small lvl_'.$item->level.'">'; Note: Your code was missing a closing double quote for the class attribute as well.


9

You need to change the Group parent to registered (or any other than Public, Guest). As users from Public usergroup are not allowed to login at website. Or you need to change the permissions of your newly created usergroup.


8

Joomla uses PHPMailer as mail handler. PHPMailer has a nice SMTP log if you turn it on. You can do this by setting the SMTPDebug variable to true $mailer = JFactory::getMailer(); $mailer->SMTPDebug = true; $mailer->setSender($settings->sender); $mailer->addRecipient($settings->to); $mailer->setSubject($settings->subject); $mailer->...


8

I assume that you have run your site through Google Page speed, and you are indeed looking at reducing the page response time i.e. time taken by your markup to be sent to the browser. The most likely culprits for these are heavy queries. Turn on the debug and look at the bottom of the page to find out which are the most heavy queries and remove or reduce ...


8

JHtml::script has additional logic included. See http://api.joomla.org/cms-3/classes/JHtml.html#method_script for the API reference By default it will detect debug setting and browser used and load the matching script. For example when debug is enabled it will load an uncompressed version of the file if present. There are optional settings which allow to ...


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 ...


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