ݺߣ

ݺߣShare a Scribd company logo
Francesco Abeni
Sviluppo di estensioni per
Joomla: BEST PRACTICES
@f_abeni
http://www.gibilogic.com
Francesco Abeni
Sviluppo di estensioni per
Joomla: BEST PRACTICES
@f_abeni
http://www.gibilogic.com
Sviluppatore Joomla / PHP
GiBiLogic
https://extensions.gibilogic.com
Watchful
https://watchful.li
DAI LA CERA
TOGLI LA CERA
...ma non sempre
la stessa cera
Usa la LINEA DI
COMANDO, Luke!
Usa GIT
e GitHub
Usa un IDE
decente
(Netbeans, PHPStorm)
CARTELLE
convenzionali
build
docs
release
src
com_jfestival
admin
site
mod_jfestival_talks
plg_search_jfestival
tests
LIBRERIE STANDARD
(jQuery, Bootstrap)
Sai cosa è una CDN?
Uniformati!
PSR FTW!
JTABLE
l'essenziale è invisibile
agli occhi
public function check() {
$user = JFactory::getUser();
if ($this→isAdminUser($user)) {
return true;
}
if ($this→isOwner($user)) {
return true;
}
return false;
}
public function store($updateNulls=false) {
$this→params = json_encode($this→params);
return parent::store($updateNulls);
}
public function load($keys=null, $reset=true) {
$row = parent::load($keys, $reset);
$row→params = json_decode($row→params);
return $row;
}
JMODEL
il tuo magazziniere di
fiducia!
public function get($id) {
$row = JTable::getInstance(
“Talks”, “JfestivalTable”
);
$row→load($id);
return $row;
}
public function getByFields($speaker, $time) {
$row = JTable::getInstance(
“Talks”, “JfestivalTable”
);
$row→load(array(
“name” => “Francesco Abeni”,
“date” => “2015-07-04”
));
return $row;
}
private function getBaseQuery() { // STEP 1
$db = JFactory::getDatabase();
$query = $db->getQuery(true)
→select(“*”)
→from(“#__jfestival_talks”);
return $query;
}
private function buildQuery() { // STEP 2
$query = $this→getBaseQuery();
$filterName = $this→getState(“name”, “”);
if ($filterName) {
$query→where(
“name LIKE '%$filterName%'
);
} //...
return $query;
}
public function getList() {
$db = JFactory::getDbo();
$db→setQuery($this→buildQuery());
try { return $db→loadObjectList(); }
catch (Exception $e) {
JLog::addLog(
$e→getMessage(), JLog::ERROR
);
return array();
}
}
JCONTROLLER / JVIEW
a dieta!
JLOG
non potrai più
farne a meno
public function __construct(...) {
JLog::addLogger(
array(
“text_file” => “jfestival.talks.log.php”
),
JLog::ALL,
'jfestival.talks'
);
}
public function whatever(...) {
JLog::add(
'A debug message',
JLog::DEBUG, 'jfestival.talks'
);
JLog::add(
'An info message',
JLog::INFO, 'jfestival.talks'
);
}
Proprietà privata
protetta e pubblica
public function get($id) { … }
protected function buildQuery() { … }
private function getName() { … }
public $id; // “$object→id” funziona
vs.
private $id; // “$object→id” NON funziona
public function getId() { return $this→id; }
OGGETTI
del discorso
Talks
JfestivalTableTalks
JfestivalModelTalks
JfestivalControllerTalks
JfestivalViewTalks
tmpl/default.php
tmpl/list.php
tmpl/edit.php
Talks
Speakers
Rooms
Sponsors
Attendees
Helpers!
GRAZIE
per voler essere
programmatori
migliori!
Qualche risorsa in ordine sparso
● BOOTSTRAP: http://getbootstrap.com/
● JQUERY: https://jquery.com/
● CDN: https://www.maxcdn.com/
● NETBEANS: http://netbeans.org/
● GITHUB: https://github.com/
● PSR: http://www.php-fig.org/
● BLOG: https://extensions.gibilogic.com/blog.html

More Related Content

Francesco abeni joomla_extensions_best_practices