Some useful Joomla Codes and Tricks

Redirect with some message
$app = JFactory::getApplication();
$link = JRoute::_('index.php?option=com_users&view=login');
$app->redirect($link, $msg, 'warning');

Access check: If this user is allowed to access the component?
if (!JFactory::getUser()->authorise('yourcomponentname.yourdefindaccess', 'com_yourcomponentname')) {
     //do actions like raise error or redirect

Raise warning or error
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));

SEF redirect
$mainframe = JFactory::getApplication();
$mainframe->redirect(JRoute::_("index.php?option=com_yourcomponentname&view=yourcomponentview", false));

Transaction in joomla
$db = JFactory::getDbo();
try {
      //code here
      $rolledBack = $db->transactionCommit();
} catch (Exception $e) {

Check if SEF url is on and get menu alias if on
$conf = &JFactory::getConfig();
if( $conf->get('sef') == 1 ){
      $menu = JSite::getMenu();
      $alias = $menu->getItem(483)->alias;
Post a Comment