Is it frontpage? How to check in Joomla! multilaguage site?

Unfortunately no way to easy checking current page on frontpage or not in Joomla! when you use multilanguage mode.
Possible solution:

$app = JFactory::getApplication();
$menu = $app->getMenu();
$lang = JFactory::getLanguage();

if ($menu->getActive() == $menu->getDefault($lang->getTag())) {
    echo 'Frontpage detected';
} else {
    echo 'NOT frontpage';
}

Try to check…

Can’t find any languages after click “Find languages” in my Joomla 3.x

If your button “Find languages” doesn’t work in your Joomla 3.x site then possible problem in 2 database tables.
1. Firstly, check #__extensions and find type=’language’ and element=’en-GB’ and get it extension_id (default = 600)
So, next…
Continue reading Can’t find any languages after click “Find languages” in my Joomla 3.x

Joomla error instalation of component issue

If you install some component on your site and get this errors:

Warning
JFolder::create: Infinite loop detected.
Warning: Failed to move file!

and

Error:
Archive does not exist
Unable to find install package

 

Then 97% error in your configuration file.
Please go to admin area and
Continue reading Joomla error instalation of component issue

Joomla! pagination bug (3.3.4 – 3.3.6) FIX

When you click to go to the second+ page and then attempt to go back to the first/start page, you will actually stay on the same(second+) page.
Here instructions on how to fix ↓
1. Go to the libraries/cms/router/ folder.
2. Create a backup of file – site.php.
3. Change site.php with an editor.
Search this code:

if ($this->_mode == JROUTER_MODE_SEF && $route)
{
    $limitstart = (int) $uri->getVar('limitstart');
 
    if ($limitstart > 0)
    {
        $uri->setVar('start', $limitstart);
    }
 
    $uri->delVar('limitstart');
}

and replace on this:

if ($this->_mode == JROUTER_MODE_SEF && $route)
{
    if ($limitstart = $uri->getVar('limitstart'))
    {
        $uri->setVar('start', (int) $limitstart);
        $uri->delVar('limitstart');
    }
}

4. Save changed site.php.
5. Check… and profit )

How to create/use Joomla! editor? JFactory::getEditor()

Example (short version in J!3.x)

$default_value = JFactory::getApplication()->input->get('your_field_name','');
$editor = JFactory::getConfig()->get('editor');
$editor = JEditor::getInstance($editor);
echo $editor->display( 'your_field_name', $default_value, 250, 250, 20, 20);

In Joomla! 2.5 the parameters list for the display() function has been lengthened, so to use specific display parameters in 2.5:

$editor =& JFactory::getEditor();
$params = array( 'smilies'=> '0' , 'style'  => '1' , 'layer'  => '0' , 'table'  => '0' ,'clear_entities'=>'0' );
echo $editor->display( 'desc', '', '400', '400', '20', '20', false, null, null, null, $params );

Allow html code in JRequest

How to create HTML select lists in Joomla!

If you need create some HTML select list with items then you can use Joomla API.
Joomla! provide special class JHTML for creating form elements, such as selectlist, radiolist, booleanlist and etc…
Most popular. Get data from database and create selectlist.
Example ↓

$selected = JFactory::getInt('selectlist_name', 0); 

$db = JFactory::getDBO();
    $query = "SELECT `id` AS `value`, `title` AS `text` FROM `#__your_table` WHERE `cid`=1";
$db->setQuery($query);
$items_from_db = $db->loadObjectList();

$selectlist_data[] = JHTML::_('select.option',  '0', "- Select item -", 'value', 'text' );
$selectlist_data = array_merge( $selectlist_data, $items_from_db);

$list = JHTML::_( 'select.genericlist',
                    $selectlist_data, 
                    'selectlist_name', 
                    'size="1" class="inputbox selectlist"', 
                    'value', 'text', 
                    $selected, 'selectlist_id', 
                    true
);
echo $list;

Result ↓

Set and get cookies in Joomla CMS

Now, it’s time to learn how to use cookies in Joomla!
If you want save some information in cookie or get some value from cookies then you can use $jcookie = JFactory::getApplication()->input->cookie;
Example ↓

$app = JFactory::getApplication();
$jinput = $app->input;
$jcookie  = $jinput->cookie;

$cookie_value = $jcookie->get( 'cookie_name', null); // Get cookie data  ($name, $defaultValue)

$jcookie->set( 'cookie_name', 'cookie_value', 0); // Set cookie data ($name, $value, $expire) $expire == 0: cookie lifetime is of browser session.

Continue reading Set and get cookies in Joomla CMS

How to set/get session value in Joomla! CMS?

Now, it’s time to learn how to use sessions in Joomla!
If you want save some information in session or get some value from session then you can use $session = JFactory::getSession();
Example ↓

$param_value = 'test session text'; // Note: also, you can store objects and arrays
$session = JFactory::getSession();
$session->set('param_value_name',$param_value); // set session value
$param_value = $session->get('param_value_name'); // get session value

More about JSession here: About JSession
Also, you cas see article about set/get cookies in Joomla!

How to use modal windows in Joomla! ?

Firstly you need write in the View file:

JHTML::_( 'behavior.modal' ); 

After you need write html a link with special params:

  • class=”modal”
  • rel=”{handler: “iframe”, size: {x: 500, y: 500}, onClose: function() {}}”

Example ↓

<a class="modal" rel="{handler: "iframe", size: {x: 500, y: 500}, onClose: function() {}}" href="http://blog.tormix.com" title="">
Modal link text
</a>

Parameter in XML form structure field for allowing HTML tags

When you are using XML form structure you can use editor form field type.
In that case for allowing HTML tags you have to use the attribute:

filter=’safehtml’

to allow saving the content with html tags.
Example ↓

<field
name="field_desc"
type="editor"
filter="safehtml"
width="350"
height="80"
label="COM_YOURCOMPONENT_EDITOR_FIELD_LABEL"
description="COM_YOURCOMPONENT_EDITOR_FIELD_DESC"
cols="20"
rows="3"
class=""
default=""
/>

Continue reading Parameter in XML form structure field for allowing HTML tags

Allow HTML code in JRequest

use html

If you need to get HTML code from JRequest then you need to use special parameter:

JREQUEST_ALLOWHTML

Example (Joomla! 1.6.x-3.x) ↓

$value = JRequest::getVar( 'field_name', '', 'post', 'string', JREQUEST_ALLOWHTML );

Note ↓

      JREQUEST_NOTRIM – prevents trimming of whitespace
      JREQUEST_ALLOWRAW – bypasses filtering
      JREQUEST_ALLOWHTML – allows most HTML. If this is not passed in, HTML is stripped out by default.

Continue reading Allow HTML code in JRequest

How to get last insert id after insert in Joomla database?

Get last id
Joomla solution for get last insert ID after insert a new row in J! database:

$db->insertid();

Example ↓

$query = $db->getQuery(true);
$query->insert('#__test_table');
$query->set('`user_id`='.(int)$uid);
$db->setQuery($query);
$db->query();
$last_id = $db->insertid();

In native PHP ↓
Object oriented style

$last_id = $mysqli->insert_id;

Continue reading How to get last insert id after insert in Joomla database?