SlideShare a Scribd company logo
Joomla Extensions
Development Best
Practices
Francesco Abeni
GiBiLogic
extensions.gibilogic.com
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
¡Hola, mundo!
Shameless self-promotion
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Francesco
Abeni
sPrintAddCSSPizzaBox
About this speech
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
The quality of code in the Joomlasphere
Today roadmap:
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● Tools
● Files and folders
● Reuse software
● MVC
● Other tips
● Conclusions
Feedback please!
No dev course
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Our target
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Good = not bad
Excellent = above the average
Good is enough for today
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
IDE basic features
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● multiple files edit
● syntax highlighting
● index for methods and variables
● autocompletion
● autoformatting
● compiler
● versioning / unit testing / phpdoc / ...
Some IDEs
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Versioning
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
http://git-scm.com/book
Standard
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Everything in its right place
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Backend ● administrator
○ components
■ com_componentname
● componentname.xml
● componentname.php
● controllers
● models
● views
Everything in its right place
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Backend ● administrator
○ components
■ com_componentname
● ...
● config.xml
● install.php
● sql
● tables
● helpers
● media
○ com_componentname
■ css
■ js
■ img
● components
○ com_componentname
■ componentname.php
■ controllers
■ models
■ views
Everything in its right place
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Frontend
● images
○ com_componentname
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
CSS / JS
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Use existing libraries
JavaScript
● MooTools (since Joomla 1.5)
● JQuery (since Joomla 2.5)
CSS + JavaScript
● Bootstrap (since Joomla 3.x)
P.S. got conflicts? Use JQueryEasy plugin.
CSS out of the door
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Don't:
<div>...</div>
<br style="clear: both">
<div style="height: 200px">...</div>
Do:
<link rel=”stylesheet” href=”/media/componentname/styles.css”>
...
<div class=”clearfix”>...</div>
<div class="fixedheight">...</div>
.clearfix { … }
.fixedheight { height: 200px }
JS out of the door
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<button id="submit" type=submit" value="ClickMe!" onclick="validateForm()" />
Do:
<script src=”/media/componentname/js/script.js”>
<button id="submit" type=submit" value="ClickMe!"/>
document.addEvent('load',function(){
$('submit').addEvent('click',function(){
validateForm();
});
});
Don't:
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Joomla framework
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● JApplication
● JDatabase
● JUser
● JSession
● JDocument
● JHTML
● JForm
● JConfig
● JUri
● JFile
● JFolder
● JLog
● JFilterInput
● JError and JException
● JDate
● JUtilities
● JVersion
● JLayout
PHP functions and classes
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● pcre
● trim
● usort
● array_map
● array_unique
● json_encode
● json_decode
● microtime(true)
● glob
● curl
● DateTime
● Standard PHP Library
● Exception
● SimpleXML
● TCPDF
● PHPMailer
PHP version
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● 16. Dec 2010: PHP 5.2 end of life
● 11. Jul 2013: PHP 5.3 end of life
● 01. Mar 2012: PHP 5.4 released
● 20 Jun 2013: PHP 5.5 released
● PHP 5.4 is 40% faster than PHP 5.2
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Real objects
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
book writer library
Bad design sample
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● views/search
● views/editbook
● views/book
● views/books
● views/booksauthor
● views/topten
Don't:
The controller
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● Filters input
● Decides what to do
● Checks access permissions
● Executes task(s)
● Optionally, calls the view
The model
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● Retrieves object data
● Validates object data
● Gets object data
● Saves object data
● Hates to be mistaken as an helper
The view
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● Ask the model for data
● Display object(s)
● Uses layouts!
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Header comment
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
/**
* @version mybooks.php 2013-08-10 15:23:00Z zanardi
* @package GiBi MyBooks
* @author GiBiLogic
* @authorUrl http://www.gibilogic.com
* @authorEmail info@gibilogic.com
* @copyright Copyright (C) 2013 GiBiLogic. All rights reserved.
* @license GNU/GPL v2 or later
* @description Backend entry point
*/
Entry point
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
...
defined('_JEXEC') or die();
jimport('joomla.application.component.controller');
$view = JFactory::getApplication()->input->get('view', 'book');
$task = JFactory::getApplication()->input->get('task', 'index');
JFactory::getApplication()->input->set('task', "$view.$task");
$controller = JController::getInstance('MyBooks');
$controller->execute($task);
$controller->redirect();
Controller - part 1
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
...
defined('_JEXEC') or die('The way is shut!');
jimport('joomla.application.component.controlleradmin');
/**
* MyBooksControllerBook class.
*
* @see JControllerAdmin
*/
class MyBooksControllerBook extends JControllerAdmin
{
/**
* Controller's view.
*
* @var JView
*/
private $view;
...
Controller - part 2
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
...
/**
* Class constructor.
*
* @param type $config
*/
public function __construct($config = array())
{
parent::__construct($config);
$this->model = $this->getModel();
$this->view = $this->getView(JFactory::getApplication()->input->get('view',
'book'), 'html');
$this->view->setModel($this->model, true);
$this->view->setModel($this->getModel('Author', 'MyBooksModel'), false);
$this->view->setModel($this->getModel('Editor', 'MyBooksModel'), false);
}
...
Controller - part 3
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
...
public function index()
{
$this->view->setLayout('index')
$this->view->display();
}
public function create()
{
$this->view->setLayout('create');
$this->view->display();
}
public function save()
{
$data = JFactory::getApplication()->input->get('jform', null);
if (!$data || !$this->model->validate($data)) {
$msg = 'Invalid data!';
$type = 'error';
$this->setRedirect('index.php?option=com_mybooks&view=book&task=create',
$msg, $type);
return false;
}
Model - part 1
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
...
defined('_JEXEC') or die('The way is shut!');
jimport('joomla.application.component.model');
jimport('joomla.html.pagination');
class MybooksModelBook extends JModel
{
private $table = '#__mybooks_book';
public function __construct($config = array())
{
parent::__construct($config);
$app = JFactory::getApplication();
$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app-
>getCfg('list_limit'), 'int');
$limitstart = $app->input->get('limitstart', 0, '', 'int');
$this->setState('limit', $limit);
$this->setState('limitstart', $limitstart);
$this->setState('author_id', $app->getUserStateFromRequest('com_mybooks.filters.
author_id', 'author_id', 0, 'int'));
}
Model - part 2
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
...
public function getList() {
return $this->_getList(
$this->buildQuery(), $this->getState('limitstart'), $this->getState('limit')
);
}
public function getLast() {
$query = $this->_db->getQuery(true);
$query->select('*')->from($this->table)->orderby('created_at DESC');
$this->_db->setQuery($query,0,1);
$results = $this->_db->loadObjectList('id');
return $results ? $results : array();
}
public function getLastByAuthor($author_id) {
$query = $this->_db->getQuery(true);
$query->select('*')->from($this->table)->where(“author_id = '$author_id'”)-
>orderby('created_at DESC');
$this->_db->setQuery($query,0,1);
return $this->_db->loadObject();
}
Model - part 3
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
...
public function create($data) {
if (!$data) {
return 0;
}
$data['created_at'] = date('Y-m-d H:i:s');
$query = $this->_db->getQuery(true);
$query->insert($this->table)->columns(array_keys($data))->values(sprintf("'%s'",
implode("','", array_values($data))));
$this->_db->setQuery($query);
return false === $this->_db->execute() ? 0 : $this->_db->insertid();
}
...
Model - part 4
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
...
public function delete($ids) {
$query = $this->_db->getQuery(true);
$query->delete()->from($this->table)->where('id IN '.implode(',', $ids));
return false !== $this->_db->execute();
}
public function getPagination(){
return new JPagination(
$this->_getListCount($this->buildQuery()), $this->getState('limitstart'),
$this->getState('limit')
);
}
private function buildQuery(){
$where = $this->buildWhere();
$query = $this->_db->getQuery(true);
return $query->select('*')->from($this->table)->where($where)->orderby
('created_at DESC');
}
...
View - part 1
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
...
defined('_JEXEC') or die('The way is shut!');
jimport('joomla.application.component.view');
class MyBooksViewBook extends JView
{
public function display($tpl = null)
{
$this->pagination = $this->getModel()->getPagination();
$this->filter_author_id = $this->getModel()->getState('author_id');
$this->books = $this->getModel()->findAll();
$this->authors = $this->getModel('Authors')->getList();
$this->editors = $this->getModel('Editors')->getList();
$this->addToolbar($tpl);
parent::display($tpl);
}
View - part 2
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
...
protected function addToolbar($tpl){
$methodName = 'addToolBar' . ucfirst(!$tpl ? 'default' : $tpl);
$this->{$methodName}();
}
private function addToolBarDefault(){
JToolBarHelper::title(JText::_('COM_MYBOOKS') . ': ' . JText::_
('COM_MYBOOKS_BOOK_LIST'));
JToolBarHelper::addNew('create');
JToolBarHelper::preferences('com_mybooks');
JToolBarHelper::divider();
JToolBarHelper::deleteList('COM_MYBOOKS_BOOK_LIST_DELETE_CONFIRM', 'delete');
}
private function addToolBarCreate(){
JToolBarHelper::title(JText::_('COM_MYBOOKS') . ': ' . JText::_
('COM_MYBOOKS_BOOK_NEW'));
JToolBarHelper::apply('save');
JToolBarHelper::divider();
JToolBarHelper::back('JTOOLBAR_BACK', 'index.php?option=com_mybooks');
}
}
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Helpers
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Common (usually static) functions not related
to a specific object
● Get date / time / external info
● Format date and numbers
● Build title and/or other HTML snippets
● Log/error management
● Handle CURL connections
Table classes
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Interface to and from the database
Active Record pattern
● Define table name and unique id
● load, store, delete, and so on
Table classes - sample code
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
<?php
class TableBook extends JTable
{
public function __construct(&$db)
{
parent::__construct(‘#__books’, ‘id’, $db);
}
}
Layouts
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Page types related to a single view (object)
"tmpl" subfolder (template override)
● List
● Single item (readonly)
● Single item (edit form)
● Blog
● ...
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
System messages
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
$app = JFactory::getApplication();
$app->enqueueMessage( $msg, $type )
JError / JException / JLog
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Error handling vs. logging
● JError is deprecated
● JException is deprecated
● Use PHP Exception class(es)
● JLog is a way to track what's happening
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Visibility
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Variables and methods
● "var ..." is deprecated since PHP 5.1.2
● public : available from other classes
● private : available only from the class
● protected : available from the class and
from inherited or parent classes
Constants
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● constants instead of variables
● drop DS
● drop DIRECTORY_SEPARATOR
● use Joomla constants:
http://docs.joomla.org/Constants
● warning: JPATH_SITE vs JPATH_BASE vs
JPATH_ROOT vs JPATH_ADMINISTRATOR
Versioning
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
● version format: major.minor.release (es. v3.1.5)
● variant: v3.1.5 Free, v3.1.5 Pro
And the road goes on and on
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Thanks :)
f.abeni@gibilogic.com
@f_abeni / @gibilogic
http://www.slideshare.net/FrancescoAbeni/best-practices-for-joomla-extensions-developers-25353320
Francesco Abeni for GiBiLogic
http://extensions.gibilogic.com - info@gibilogic.com
Feedback please!

More Related Content

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 

Featured

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Best practices for Joomla extensions developers - Joomla Day 2013

  • 1. Joomla Extensions Development Best Practices Francesco Abeni GiBiLogic extensions.gibilogic.com
  • 2. Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ¡Hola, mundo!
  • 3. Shameless self-promotion Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Francesco Abeni sPrintAddCSSPizzaBox
  • 4. About this speech Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com The quality of code in the Joomlasphere
  • 5. Today roadmap: Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● Tools ● Files and folders ● Reuse software ● MVC ● Other tips ● Conclusions Feedback please!
  • 6. No dev course Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 7. Our target Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Good = not bad Excellent = above the average Good is enough for today
  • 8. Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 9. IDE basic features Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● multiple files edit ● syntax highlighting ● index for methods and variables ● autocompletion ● autoformatting ● compiler ● versioning / unit testing / phpdoc / ...
  • 10. Some IDEs Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 11. Versioning Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com http://git-scm.com/book
  • 12. Standard Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 13. Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 14. Everything in its right place Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Backend ● administrator ○ components ■ com_componentname ● componentname.xml ● componentname.php ● controllers ● models ● views
  • 15. Everything in its right place Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Backend ● administrator ○ components ■ com_componentname ● ... ● config.xml ● install.php ● sql ● tables ● helpers
  • 16. ● media ○ com_componentname ■ css ■ js ■ img ● components ○ com_componentname ■ componentname.php ■ controllers ■ models ■ views Everything in its right place Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Frontend ● images ○ com_componentname
  • 17. Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 18. CSS / JS Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Use existing libraries JavaScript ● MooTools (since Joomla 1.5) ● JQuery (since Joomla 2.5) CSS + JavaScript ● Bootstrap (since Joomla 3.x) P.S. got conflicts? Use JQueryEasy plugin.
  • 19. CSS out of the door Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Don't: <div>...</div> <br style="clear: both"> <div style="height: 200px">...</div> Do: <link rel=”stylesheet” href=”/media/componentname/styles.css”> ... <div class=”clearfix”>...</div> <div class="fixedheight">...</div> .clearfix { … } .fixedheight { height: 200px }
  • 20. JS out of the door Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <button id="submit" type=submit" value="ClickMe!" onclick="validateForm()" /> Do: <script src=”/media/componentname/js/script.js”> <button id="submit" type=submit" value="ClickMe!"/> document.addEvent('load',function(){ $('submit').addEvent('click',function(){ validateForm(); }); }); Don't:
  • 21. Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 22. Joomla framework Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● JApplication ● JDatabase ● JUser ● JSession ● JDocument ● JHTML ● JForm ● JConfig ● JUri ● JFile ● JFolder ● JLog ● JFilterInput ● JError and JException ● JDate ● JUtilities ● JVersion ● JLayout
  • 23. PHP functions and classes Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● pcre ● trim ● usort ● array_map ● array_unique ● json_encode ● json_decode ● microtime(true) ● glob ● curl ● DateTime ● Standard PHP Library ● Exception ● SimpleXML ● TCPDF ● PHPMailer
  • 24. PHP version Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● 16. Dec 2010: PHP 5.2 end of life ● 11. Jul 2013: PHP 5.3 end of life ● 01. Mar 2012: PHP 5.4 released ● 20 Jun 2013: PHP 5.5 released ● PHP 5.4 is 40% faster than PHP 5.2
  • 25. Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 26. Real objects Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com book writer library
  • 27. Bad design sample Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● views/search ● views/editbook ● views/book ● views/books ● views/booksauthor ● views/topten Don't:
  • 28. The controller Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● Filters input ● Decides what to do ● Checks access permissions ● Executes task(s) ● Optionally, calls the view
  • 29. The model Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● Retrieves object data ● Validates object data ● Gets object data ● Saves object data ● Hates to be mistaken as an helper
  • 30. The view Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● Ask the model for data ● Display object(s) ● Uses layouts!
  • 31. Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 32. Header comment Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php /** * @version mybooks.php 2013-08-10 15:23:00Z zanardi * @package GiBi MyBooks * @author GiBiLogic * @authorUrl http://www.gibilogic.com * @authorEmail info@gibilogic.com * @copyright Copyright (C) 2013 GiBiLogic. All rights reserved. * @license GNU/GPL v2 or later * @description Backend entry point */
  • 33. Entry point Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php ... defined('_JEXEC') or die(); jimport('joomla.application.component.controller'); $view = JFactory::getApplication()->input->get('view', 'book'); $task = JFactory::getApplication()->input->get('task', 'index'); JFactory::getApplication()->input->set('task', "$view.$task"); $controller = JController::getInstance('MyBooks'); $controller->execute($task); $controller->redirect();
  • 34. Controller - part 1 Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php ... defined('_JEXEC') or die('The way is shut!'); jimport('joomla.application.component.controlleradmin'); /** * MyBooksControllerBook class. * * @see JControllerAdmin */ class MyBooksControllerBook extends JControllerAdmin { /** * Controller's view. * * @var JView */ private $view; ...
  • 35. Controller - part 2 Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php ... /** * Class constructor. * * @param type $config */ public function __construct($config = array()) { parent::__construct($config); $this->model = $this->getModel(); $this->view = $this->getView(JFactory::getApplication()->input->get('view', 'book'), 'html'); $this->view->setModel($this->model, true); $this->view->setModel($this->getModel('Author', 'MyBooksModel'), false); $this->view->setModel($this->getModel('Editor', 'MyBooksModel'), false); } ...
  • 36. Controller - part 3 Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php ... public function index() { $this->view->setLayout('index') $this->view->display(); } public function create() { $this->view->setLayout('create'); $this->view->display(); } public function save() { $data = JFactory::getApplication()->input->get('jform', null); if (!$data || !$this->model->validate($data)) { $msg = 'Invalid data!'; $type = 'error'; $this->setRedirect('index.php?option=com_mybooks&view=book&task=create', $msg, $type); return false; }
  • 37. Model - part 1 Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php ... defined('_JEXEC') or die('The way is shut!'); jimport('joomla.application.component.model'); jimport('joomla.html.pagination'); class MybooksModelBook extends JModel { private $table = '#__mybooks_book'; public function __construct($config = array()) { parent::__construct($config); $app = JFactory::getApplication(); $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app- >getCfg('list_limit'), 'int'); $limitstart = $app->input->get('limitstart', 0, '', 'int'); $this->setState('limit', $limit); $this->setState('limitstart', $limitstart); $this->setState('author_id', $app->getUserStateFromRequest('com_mybooks.filters. author_id', 'author_id', 0, 'int')); }
  • 38. Model - part 2 Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php ... public function getList() { return $this->_getList( $this->buildQuery(), $this->getState('limitstart'), $this->getState('limit') ); } public function getLast() { $query = $this->_db->getQuery(true); $query->select('*')->from($this->table)->orderby('created_at DESC'); $this->_db->setQuery($query,0,1); $results = $this->_db->loadObjectList('id'); return $results ? $results : array(); } public function getLastByAuthor($author_id) { $query = $this->_db->getQuery(true); $query->select('*')->from($this->table)->where(“author_id = '$author_id'”)- >orderby('created_at DESC'); $this->_db->setQuery($query,0,1); return $this->_db->loadObject(); }
  • 39. Model - part 3 Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php ... public function create($data) { if (!$data) { return 0; } $data['created_at'] = date('Y-m-d H:i:s'); $query = $this->_db->getQuery(true); $query->insert($this->table)->columns(array_keys($data))->values(sprintf("'%s'", implode("','", array_values($data)))); $this->_db->setQuery($query); return false === $this->_db->execute() ? 0 : $this->_db->insertid(); } ...
  • 40. Model - part 4 Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php ... public function delete($ids) { $query = $this->_db->getQuery(true); $query->delete()->from($this->table)->where('id IN '.implode(',', $ids)); return false !== $this->_db->execute(); } public function getPagination(){ return new JPagination( $this->_getListCount($this->buildQuery()), $this->getState('limitstart'), $this->getState('limit') ); } private function buildQuery(){ $where = $this->buildWhere(); $query = $this->_db->getQuery(true); return $query->select('*')->from($this->table)->where($where)->orderby ('created_at DESC'); } ...
  • 41. View - part 1 Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php ... defined('_JEXEC') or die('The way is shut!'); jimport('joomla.application.component.view'); class MyBooksViewBook extends JView { public function display($tpl = null) { $this->pagination = $this->getModel()->getPagination(); $this->filter_author_id = $this->getModel()->getState('author_id'); $this->books = $this->getModel()->findAll(); $this->authors = $this->getModel('Authors')->getList(); $this->editors = $this->getModel('Editors')->getList(); $this->addToolbar($tpl); parent::display($tpl); }
  • 42. View - part 2 Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php ... protected function addToolbar($tpl){ $methodName = 'addToolBar' . ucfirst(!$tpl ? 'default' : $tpl); $this->{$methodName}(); } private function addToolBarDefault(){ JToolBarHelper::title(JText::_('COM_MYBOOKS') . ': ' . JText::_ ('COM_MYBOOKS_BOOK_LIST')); JToolBarHelper::addNew('create'); JToolBarHelper::preferences('com_mybooks'); JToolBarHelper::divider(); JToolBarHelper::deleteList('COM_MYBOOKS_BOOK_LIST_DELETE_CONFIRM', 'delete'); } private function addToolBarCreate(){ JToolBarHelper::title(JText::_('COM_MYBOOKS') . ': ' . JText::_ ('COM_MYBOOKS_BOOK_NEW')); JToolBarHelper::apply('save'); JToolBarHelper::divider(); JToolBarHelper::back('JTOOLBAR_BACK', 'index.php?option=com_mybooks'); } }
  • 43. Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 44. Helpers Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Common (usually static) functions not related to a specific object ● Get date / time / external info ● Format date and numbers ● Build title and/or other HTML snippets ● Log/error management ● Handle CURL connections
  • 45. Table classes Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Interface to and from the database Active Record pattern ● Define table name and unique id ● load, store, delete, and so on
  • 46. Table classes - sample code Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com <?php class TableBook extends JTable { public function __construct(&$db) { parent::__construct(‘#__books’, ‘id’, $db); } }
  • 47. Layouts Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Page types related to a single view (object) "tmpl" subfolder (template override) ● List ● Single item (readonly) ● Single item (edit form) ● Blog ● ...
  • 48. Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 49. System messages Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com $app = JFactory::getApplication(); $app->enqueueMessage( $msg, $type )
  • 50. JError / JException / JLog Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Error handling vs. logging ● JError is deprecated ● JException is deprecated ● Use PHP Exception class(es) ● JLog is a way to track what's happening
  • 51. Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 52. Visibility Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Variables and methods ● "var ..." is deprecated since PHP 5.1.2 ● public : available from other classes ● private : available only from the class ● protected : available from the class and from inherited or parent classes
  • 53. Constants Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● constants instead of variables ● drop DS ● drop DIRECTORY_SEPARATOR ● use Joomla constants: http://docs.joomla.org/Constants ● warning: JPATH_SITE vs JPATH_BASE vs JPATH_ROOT vs JPATH_ADMINISTRATOR
  • 54. Versioning Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com ● version format: major.minor.release (es. v3.1.5) ● variant: v3.1.5 Free, v3.1.5 Pro
  • 55. And the road goes on and on Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com
  • 56. Thanks :) f.abeni@gibilogic.com @f_abeni / @gibilogic http://www.slideshare.net/FrancescoAbeni/best-practices-for-joomla-extensions-developers-25353320 Francesco Abeni for GiBiLogic http://extensions.gibilogic.com - info@gibilogic.com Feedback please!