Programming Modules for Joomla 1.5, 3. Create an OOP Module

download Programming Modules for Joomla 1.5, 3. Create an OOP Module

If you can't read please download the document

description

Programming Modules for Joomla 1.5 - Hour 3: Create an OOP Module (Workshop for Joomladay Norway 2011, Saturday August 13th 2011)

Transcript of Programming Modules for Joomla 1.5, 3. Create an OOP Module

Programming Joomla 1.5 Modules Hour 3: Create an OOP Moduleby Peter Martin Nickname: pe7er Twitter: @pe7er Website: www.db8.nl

13 August 2011

Hour 3 Write a Module part 2H3.1 OOP Modules H3.2 i18n Language pack (Language Files) H3.3 Distribution (Installable Module) H3.4 Modules and use of plugins Assignments: a. Create an OOP style Module b. Create Language File c. Create installable package for Module

2

3.1 Model-View-Controller (MVC)

MVC = Object-oriented programming (OOP) Separation business logic / presentation layer Business logic easier to extend the code Presentation layer Easier to change without PHP knowledge (webdesigners will love it) Template overrides (no more core hacks!) However, Modules only have view, not a controller. Therefore not MVC, but OOP (helper file = sort of Model + Controller in one)

3

3.1 Module MVC style Overview1 2 3 4

Root file

mod_db8latestweblinks.php helper.php mod_db8latestweblinks.xml /tmpl/default.php

Helper file (retrieves records from database)

Installer file (also for defining parameters)

Screen output (presentation layer)

4

3.1 Module OOP style Filesmod_db8latestweblinks.php mod_db8latestweblinks.xml helper.php index.html tmpl/index.html tmpl/default.php en-GB.mod_db8latestweblinks.ini nb-NO.mod_db8latestweblinks.ini

5

3.1 OOP Diagram: 1. root file0. Joomla 1. Root file

mod_db8latestweblinks.php //Trigger Helper file require_once (dirname(__FILE__).DS.'helper.php'); $list = modDB8LatestWeblinksHelper::getItems($params); NB: the arrows just represent a sketch. I'm not sure if it's a correct OOP diagram.

6

3.1 OOP Diagram: 2. helper file0. Joomla 1. Root file 2. Helper file 0. Joomla

helper.phpclass modDB8LatestWeblinksHelper { // [retrieve parameters] // [retrieve database records]jos_weblinks jos_modules

// [return data] }7

3.1 OOP Diagram: 3. installer file0. Joomla

not

used during process only for installing & configurationjos_modules

8

3.1 OOP Diagram: 4. scr output 10. Joomla 1. Root file 2. Helper file 0. Joomla

mod_db8latestweblinks.php //Trigger Layout file jos_modules mod_db8latestweblinks/tmpl/default.php require(JModuleHelper::getLayoutPath( 'mod_db8latestweblinks'));jos_weblinks

9

3.1 OOP Diagram: 4. scr output 20. Joomla 1. Root file 2. Helper file 0. Joomla

3. Layout file

/tmpl/default.php

10