web design, England, Britain, UK, belgium
 
Ulti Clocks content

Joomla Cheat Sheet - Joomla & VirtueMart Tips & How To's

GJC Website Design UK, Joomla Developer, VirtueMart Developer, Template Developer, web site designs, England, Britain, UK, Belgium, search-engine optimisation (SEO). Multilingual.

Home Joomla - VirtueMart Virtuemart 2 AusPost Shipping Estimator Mod

Mon

28

Apr

  • Joomla
  • Cheat Sheet

Here's a list of Joomla code snippets so that I don't have to search the forums every time I need one!

Joomla 1.5

excellent post-> http://eddify.me/posts/converting-old-extensions-to-joomla-15.html


Joomla 2.5

Find if on home page

$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';
}

or

$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault( 'en-GB' )) {
echo 'This is the front page';
}
elseif ($menu->getActive() == $menu->getDefault( 'fr-FR' )) {
echo 'Accueil';
}
.......................................................

Find current page title

$mydoc =& JFactory::getDocument();
$title = $mydoc->getTitle();
.......................................................

Std DB call

// Get a db connection.
$db = JFactory::getDbo();
 
// Create a new query object.
$query = $db->getQuery(true);
 
// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
$query->select($db->quoteName(array('user_id', 'profile_key', 'profile_value', 'ordering')));
$query->from($db->quoteName('#__user_profiles'));
$query->where($db->quoteName('profile_key') . ' LIKE '. $db->quote('\'custom.%\''));
$query->order('ordering ASC');
 
// Reset the query using our newly populated query object.
$db->setQuery($query);
 
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();
.......................................................

Find current menu text

$active = JFactory::getApplication()->getMenu()->getActive();
$title = $active->title;
.......................................................

Find current menu link from Itemid

$menuitem is the Itemid

$item = JFactory::getApplication()->getMenu()->getItem( $menuitem );
$url = JRoute::_($item->link . '&Itemid=' . $item->id);
.......................................................

Get a var

$success = JRequest::getVar('success');
.......................................................

Just show the component

&tmpl=component
.......................................................

Show messages in component

$document = & JFactory::getDocument();
$renderer = $document->loadRenderer('message');
$msg=@$renderer->render();
.......................................................

Get the messages

$messages = JFactory::getApplication()->getMessageQueue();
//this is an array of queued messages - no html
.......................................................

Clear joomla messages

$app = JFactory::getApplication();
$app->set( '_messageQueue', '' ); //clear messages
.......................................................

Joomla session
set

$session = JFactory::getSession();
$previousValue = $session->set('myValue', $value,'myNameSpace');

get

$session = JFactory::getSession();
$value = $session->get('myValue', myDefault,'myNameSpace');
.......................................................

Add module to component
You can also pass prameters - form {"btuser":"83"}

$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('modules');
$position = 'comuser';
$options = array('style' => 'raw','params' => '{"btuser":"'.$userid.'"}' );
echo $renderer->render($position, $options, null);

or

$modules =& JModuleHelper::getModules('position-4');
foreach ($modules as $module)
{
echo JModuleHelper::renderModule($module);
}
.......................................................

Add js & css

$document = JFactory::getDocument();
$document->addScript(Juri::base() .'components/com_musicbattle/assets/js/imageflow.js');
$document->addStyleSheet(Juri::base() .'components/com_musicbattle/assets/css/imageflow.css');
.......................................................

Get User etc

$user =& JFactory::getUser();
$userid = $user->get('id');
$groups = JAccess::getGroupsByUser($userid, false);
if(in_array(7, $groups)){
echo 'only visible for admin';
}else{
echo 'only not an admin';
}
.......................................................

Add a lang file

$lang = JFactory::getLanguage();
$extension = 'com_helloworld';
$base_dir = JPATH_SITE;
$language_tag = 'en-GB';
$reload = true;
$lang->load($extension, $base_dir, $language_tag, $reload);
.......................................................

Joomla 3.0

common upgrade problems

replace globals  - J3

$mainframe ($app)
$mainframe = JFactory::getApplication();

$database
$database = JFactory::getDbo();

$option
$option = JRequest::getCmd('option');

$limit
$limit = $mainframe->getCfg('list_limit');
.......................................................

Admin toolber buttons do nothing - J3

replace JToolBarHelper::save();
with JToolbarHelper::save('event.save');

event is the subcontroller name
.......................................................

Call to undefined method Joomla\Registry\Registry::getValue() - J3

replace JRegistry::getValue()
with JRegistry::get()

event is the subcontroller name
.......................................................

 

Admin call subcontroller - J3

replace index.php?option=com_ccg&view=events&task=edit&cid[]='. $row->id;
with 'index.php?option=com_ccg&task=events.edit&cid[]='. $row->id;

events is the subcontroller name
.......................................................

JTable::getInstance('event','Jtable') returns nothing  - J3

add   JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/tables');
.......................................................

Declaration of JxController::display() should be compatible with JControllerLegacy::display($cachable = false, $urlparams = Array)  - J3

replace function display()
with function display($cachable = false, $urlparams = false)
.......................................................

Fatal error: Class 'JFolder' not found  - J3

add jimport('joomla.filesystem.folder');
.......................................................

cannot extend from interface JController  - J3

replace class JMainController extends JController
with class JMainController extends JControllerLegacy
.......................................................

admin com menu gives 404 (legacy J1.5->2.5  - J3

rename admin.com_mycom.php
to com_mycom.php
.......................................................

Call to undefined method Joomla\Registry\Registry::loadJSON() - J3

replace loadJSON
with  loadString
.......................................................

Fatal error: Class 'JRegistry' - J3

old extension my not load the JRegistry class fix libraries - add
// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';
// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
.......................................................

Use of undefined constant DS - J3

Use of undefined constant DS - add
if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
or replace all 'DS' with /
.......................................................

500 - Html: :jquery is not supported - J3

Replace JHtml::_('behavior.jquery');
with JHtml::_('jquery.framework');
.......................................................

500 - JHtmlBehavior::mootools not found or JHtml::core(); - J3

Replace JHtml::_('behavior.mootools');
with JHtml::_('behavior.framework');
.......................................................

500 - Class 'JParameter' not found - J3

Replace if(defined( '_JEXEC' )) return new JParameter($param, $path);
with            if(defined( '_JEXEC' )) return new JRegistry($param, $path);
.......................................................

Joomla 3 snippets

Bootstrap tooltips - J3

JHTML::_('bootstrap.tooltip');

<h5 class="hasTooltip" data-placement="right" title="This is the tooltip">

Stye with classes: .tooltip, .tooltip-inner, .tooltip-arrow
Positional dependent:  .tooltip.left .tooltip-arrow, .tooltip.top .tooltip-arrow etc
.......................................................

Bootstrap modal - J3

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

<a rel="size: {x: 900, y: 600}" onclick=" return false;" href="/component/content/17.html?tmpl=component" title="example popup" class="btn modal">Popup </a>

Stye with: media/system/css/modal.css
.......................................................
 
Find current page title
 
$mydoc =& JFactory::getDocument(); 
$title = $mydoc->getTitle();
.......................................................
Last Updated on Monday, 13 April 2015 13:17
 
VirtueMart
Your Cart is currently empty.

Latest Joomla & VirtueMart Tips

See all tips & examples



Joomla Cheat Sheet|Joomla & VirtueMart Tips & How To's



GJC Website Design UK, Joomla Developer, VirtueMart Developer, Template Developer, web site designs, England, Britain, UK, Belgium, search-engine optimisation (SEO). Multilingual.


jfactory, joomla, replace, menu, query, tooltip, app, echo, document, getapplication, jhtml, add, admin, class, messages, title, user, getdocument, array, php, page, jregistry, option, css, jpath, component, behavior, renderer, registry, display, libraries, base, session, bootstrap, false, profile, subcontroller, event, amp, getmenu

|

We use cookies to improve our website and your experience when using it. Cookies used for the essential operation of the site have already been set.
To find out more about the cookies we use and how to delete them, see our privacy policy.

I accept cookies from this site.