際際滷

際際滷Share a Scribd company logo
Framework on
Framework (FOF)
Rapid component development
What is FOF?
Or, rather, what's it not?
Not a fork of another framework
(or trying to sell you a fork of your favourite CMS...)
Not the best thing since sliced bread
Not A Real Framework
        (NARF)
FOF extends the Joomla! MVC API
     It does not replace or undermine it
FOF is licensed under GNU/GPL
     Note: its GPL version 3 or later
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)
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)
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
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!
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
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.
HMVC


 Include the results of component views anywhere
 (other views, other component, modules, ...)

 FOFDispatcher::getTmpInstance(com_foobar,
 items, array(layout => fancy))->dispatch();
Reuse view templates


 Load a view template from another view,
 component, ...

 echo $this->loadAnyTemplate('site:com_foobar/
 item/form');
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
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
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.
FOF Resources
 http://akeeba.info/fof
You ask, I reply
The End
is the beginning

More Related Content

FOF Rapid Application Development on Joomla! - Joomla! Day Denmark 2012

  • 1. Framework on Framework (FOF) Rapid component development
  • 2. What is FOF? Or, rather, what's it not?
  • 3. Not a fork of another framework (or trying to sell you a fork of your favourite CMS...)
  • 4. Not the best thing since sliced bread
  • 5. Not A Real Framework (NARF)
  • 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.
  • 20. You ask, I reply
  • 21. The End is the beginning

Editor's Notes