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 current page title

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

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

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');
.......................................................

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');
.......................................................

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

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 - 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
.......................................................
 
Last Updated on Friday, 27 March 2015 23:47
 
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, tooltip, replace, document, messages, jhtml, css, class, getapplication, getdocument, behavior, add, base, display, libraries, title, bootstrap, renderer, session, option, php, defined, false, component, undefined, array, framework, mainframe, jregistry, modal, app, jquery, limit, lang, menu, extension, jpath, itemid, item

|

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.