FOF is a framework that extends the Joomla MVC API to promote convention over configuration and reuse of components. It aims to reduce code duplication and make component development easier. Key features include a query builder, HMVC support, reusable view templates, automatic language and media file handling, and built-in JSON and CSV output. FOF follows common conventions for models, controllers, and views to minimize configuration.
1 of 21
Downloaded 47 times
More Related Content
FOF Rapid Application Development on Joomla! - Joomla! Day Denmark 2012
6. FOF extends the Joomla! MVC API
It does not replace or undermine it
7. FOF is licensed under GNU/GPL
Note: its GPL version 3 or later
8. Design goals
DRY - Don't Repeat Yourself. Copying & pasting code is
the source of all evil.
Write less, do more - less code, less failure points
It should never impose its own way of thinking. Gets
out of your way when you want to work around it.
Backwards compatibility - no surprising, quantum
changes every few days
Joomla! version abstraction (1.5, 2.5 and 3.0 supported)
9. Key features
Convention over configuration, Rails style
Use a query builder, even on Joomla! 1.5
HMVC today, not in 3 years, without relearning component
development
Easy reuse of view template files without ugly include()
Automatic language loading and easy overrides
Media files override (works like template overrides)
Automatic JSON and CSV views with no extra code
Automatic Joomla! version template overrides (e.g. default.j30.php)
10. Overview of a component
The Dispatcher is the entry point. It will setup, run and render
the MVC view
The Controller is a thin interface to push data to the model state
and instantiate views
The Model is the workhorse. Business logic goes here.
The Table class is a hybrid data adapter, controller and model
(following J!'s convention)
The View fetches model state data and renders them in a
meaningful way
The Toolbar handles the rendering of titles, buttons and so on
11. Convention over configuration in
Models
Tables are named as #__component_view, e.g.
#__todo_items
Auto increment field is named component_view_id,
e.g. todo_item_id
Magic fields: enabled, created_by, created_on,
modified_by, modified_on, locked_by, locked_on,
hits
You can override defaults without copying & pasting
code, ever. Copy & paste is the devil!
12. Convention over configuration in
Controllers
Default tasks (not RESTful!): browse, read, edit, add,
delete, save, apply, ...
Customize with onBeforeMethod and onAfterMethod
methods, e.g. onBeforeSave. Don't copy & paste code.
All MVC objects can be passed a $config array to
customize them. It "flows" from dispatcher to
component to model and view.
FOF guesses the task if it's missing based on plural/
singular view name and existence of ID in the query
13. Convention over configuration in Views
Views inherit from FOFView and its specialized
children, e.g. FOFViewHtml
Customize using the onTask methods, e.g. onBrowse
The toolbar is handled outside the view, in a
FOFToolbar descendant class. Override it with a
toolbar.php file in the component's root.
Magic toolbar methods, e.g. onItemsBrowse allow you
to customize the toolbar without copying & pasting
code.
14. HMVC
Include the results of component views anywhere
(other views, other component, modules, ...)
FOFDispatcher::getTmpInstance(com_foobar,
items, array(layout => fancy))->dispatch();
15. Reuse view templates
Load a view template from another view,
component, ...
echo $this->loadAnyTemplate('site:com_foobar/
item/form');
16. Language loading and overrides
Automatically loads component language files
(frontend and backend)
Hierarchical language overridding
English loads first
Current site/user language loads next and overrides English
17. Media files overrides
Load media files like this:
FOFTemplateUtils::addCSS('media://com_foobar/
css/frontend.css');
Media overrides are inside the template folder, e.g.
templates/tpl_example/media/com_foobar/css/
frontend.css
18. Automatic JSON and CSV views
Just add format=json or format=csv
JSON: You have an instant JSON-based remote API
for your components
CSV: You can quickly export whatever you see in the
backend to Excel, Numbers, LibreOffice, Google
Docs, etc.