Advance Component Development by Azrul Rahim

4,337 views

Published on

Advance Component Development by Azrul Rahim presentation given at CMS Expo in Denver, December 2008.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,337
On SlideShare
0
From Embeds
0
Number of Embeds
215
Actions
Shares
0
Downloads
93
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Advance Component Development by Azrul Rahim

    1. 1. Azrul Rahim
    2. 2. <ul><li>Developer of </li></ul><ul><ul><li>JomComment & MyBlog </li></ul></ul><ul><ul><li>JomSocial ( www.jomsocial.com ) </li></ul></ul><ul><li>3 years of Joomla! coding experience </li></ul><ul><li>Started with Joomla! 1.0 and now code exclusively for Joomla! 1.5 </li></ul><ul><li>Slides co-written by Toby Patterson </li></ul>
    3. 3. <ul><li>Introduction to Joomla MVC </li></ul><ul><li>Business logic in Joomla </li></ul><ul><ul><li>Examples </li></ul></ul><ul><li>Some useful utilities and libraries </li></ul><ul><ul><li>JFactory, JRequest, and others </li></ul></ul><ul><li>Introduction to some advance topics </li></ul><ul><ul><li>Error handling </li></ul></ul><ul><ul><li>Internationalization </li></ul></ul>
    4. 4. <ul><li>All component is stored in /components/ folder </li></ul><ul><li>component/com_hello/ </li></ul><ul><ul><li>hello.php </li></ul></ul>
    5. 5. <ul><li>JOOMLA 1.0 </li></ul><ul><li>JOOMLA 1.5 </li></ul>
    6. 7. <ul><li>Model – manage data and logic. </li></ul><ul><ul><li>All database calls should be here </li></ul></ul><ul><li>View – render the data from model. </li></ul><ul><ul><li>No business logic here please </li></ul></ul><ul><li>Controller – control application flow </li></ul><ul><ul><li>Interpret user request </li></ul></ul><ul><ul><li>Trigger appropriate model </li></ul></ul><ul><ul><li>Pass model to view </li></ul></ul>
    7. 8. <ul><li>http://dev.joomla.org/component/option,com_jd-wiki/Itemid,/id,tutorials:components/ </li></ul>
    8. 9. <ul><li>Minimal code here. Execute the controller </li></ul>
    9. 10. <ul><li>Process user request </li></ul><ul><li>DO NOT </li></ul><ul><ul><li>Do db calls </li></ul></ul><ul><ul><li>Echo anything! </li></ul></ul><ul><li>Pass the execution to view </li></ul>
    10. 11. <ul><li>Extends JModel </li></ul><ul><li>Your method represent business logic </li></ul>
    11. 12. <ul><li>Render the output </li></ul><ul><li>Grab data from model </li></ul><ul><li>Have direct access to the default model </li></ul>
    12. 13. <ul><li>Layout file does the final HTML output </li></ul>default.php nogreetings.php
    13. 14. <ul><li>Separate application control, data logic and view </li></ul><ul><li>The important concepts to take away are: </li></ul><ul><ul><li>Controllers represent control logic; </li></ul></ul><ul><ul><li>Models represent business/data logic; </li></ul></ul><ul><ul><li>Views represent presentation logic; </li></ul></ul><ul><ul><li>Layouts are for markup language. </li></ul></ul>
    14. 15. More on Joomla! API
    15. 16. <ul><li>MVC – JController, JModel , JView </li></ul><ul><li>JRequest – grab user POST/GET/REQUEST data </li></ul><ul><li>JText </li></ul><ul><ul><li>multi-language support </li></ul></ul><ul><ul><li>Use JText::_ ( ) and JText::sprintf( ) </li></ul></ul><ul><li>JFactory - access global objects </li></ul><ul><li>JUser – User object </li></ul>
    16. 17. <ul><li>Implement “Factory” design pattern </li></ul><ul><li>::getApplication() (instead of global $mainframe) </li></ul><ul><li>::getDBO(); </li></ul><ul><li>::getDocument(); </li></ul>
    17. 18. <ul><li>Don’t just use JRequest::getVar( ….) </li></ul><ul><li>::getWord(…) </li></ul><ul><li>::getCmd(…) </li></ul><ul><li>::getString(…) </li></ul><ul><li>::getBool(…) </li></ul><ul><li>::getFloat(…) </li></ul><ul><li>::getInt(…) </li></ul>
    18. 19. A string is series of characters. In PHP, a character is the same as a byte , that is, there are exactly 256 different characters possible. This also implies that PHP has no native support of Unicode. From php.net, definition of a string
    19. 20. <ul><li>Ensure UTF-8 integrity </li></ul><ul><ul><li>Use JString:: functions </li></ul></ul><ul><ul><li>JString::strlen(…) </li></ul></ul><ul><li>Support internationalization </li></ul><ul><ul><li>JText::_(…) </li></ul></ul><ul><ul><li>JText::sprintf(…) </li></ul></ul>
    20. 21. <ul><li>DO NOT use fopen, fread … </li></ul><ul><li>Use Joomla calls </li></ul><ul><ul><li>JFolder </li></ul></ul><ul><ul><li>JFile </li></ul></ul><ul><ul><li>JPath </li></ul></ul>
    21. 22. <ul><li>Display warning message </li></ul>$mainframe = JFactory::getApplication(); $mainframe->enqueuMessage(‘Warning’);
    22. 23. <ul><li>We want to fail fast! </li></ul><ul><li>Do not let error propagate to other part of the code </li></ul>
    23. 25. <ul><li>http://developer.joomla.org </li></ul><ul><li>http://docs.joomla.org/Developers </li></ul>

    ×