Ca programator nu trebuie sa ai o memorie "de elefant" si din acest motiv va propunem sa cititi aceste fragmente de cod atunci cand creati sau updatati un template Joomla.
1. Obtine URL-ul curent (absolut):
$uri = &JURI::getInstance();
$myabsoluteurl = $uri->toString(array('path'));
2. Obtine ID-ul articol cu articol
$db = &JFactory::getDBO();
$sql = "SELECT introtext FROM #__content WHERE id = ".intval($articleId);
$db->setQuery($sql);
$fullArticle = $db->loadResult();
if(!strlen(trim($fullArticle)))
{
$fullArticle = "Article is empty ";
}
3. Adauga fisiere JS in capul templateului (sabloanului):
$host = JURI::root(); $document =& JFactory::getDocument(); $document->addScript($host.'path/jquery-1.4.4.min.js');
4. Transmite un modul din template (sablon):
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_related_items');
$attribs['style'] = 'xhtml';
echo JModuleHelper::renderModule( $module, $attribs );
5. Obtine ID-ul user activ:
$user =& JFactory::getUser(); $user_id = $user->id;
6. Repara variabila globala $mainframe:
//old code global $mainframe; $params =& $mainframe->getParams(); //in joomla 1.7/2.5 $app =& JFactory::getApplication(); $params = $app->getParams();
7. Obtine o inregistrare din db:
$db =& JFactory::getDBO();
$query = "SELECT * FROM uk_code WHERE code = '".$_to_postcode."' LIMIT 1";
$db->setQuery($query);
if ($row = $db->loadObject ())
{
$x2 = $row->coord1;
}
8. Stabileste titlul paginii:
$document = JFactory::getDocument(); $document->setTitle($this->escape($title));
9. Detecteaza daca esti in prima pagina:
$uri =& JURI::getInstance();
$myabsoluteurl = $uri->toString(array('path'));
if($myabsoluteurl == JURI::base(true).'/')
{
$front_page = TRUE;
}
10. Obtine numele unei componente din index.php-ul templateului (sablonului) Joomla:
$comp_name = JFactory::getApplication()->input->get('option');
11. Obtine vizualizarea numelui din index.php-ul templateului (sablonului) Joomla:
$view_name = JFactory::getApplication()->input->get('view');
12. Obtine ID-ul articolului din index.php-ul templateului (sablonului) Joomla:
$article_id = JFactory::getApplication()->input->get('id');
