Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Joomla Extensions Kung Fu

14,943 views

Published on

My presentation at Joomla and Beyond 2010 Conference about popular mistakes made by Joomla extension developers.

Published in: Technology, Business
  • Login to see the comments

Joomla Extensions Kung Fu

  1. 2. Why you can believe me 4 years of experience
  2. 3. Agenda Development Design MVC Other important questions Code optimization The most popular mistakes!
  3. 4. Joomla Components development
  4. 5. Model-View-Controller
  5. 6. How many times did you see this? Model View Controller User updates manipulates sees uses
  6. 7. An application is split by 3 departments which collaborate with each other to bring you the best results, but they don’t “disturb each other” at the same time!
  7. 9. MVC Controller
  8. 10. The controller is the boss!
  9. 11. You should use a controller for Getting request data; Getting model & view instances; Updating model states; Calling model action methods (e.g. delete, save, remove); Calling view methods to render a template.
  10. 12. You should not use a controller for Database task; Manipulating model data; Rendering templates. model & view tasks
  11. 13. A Controller in Joomla
  12. 14. JController
  13. 15. display() method revealed /libraries/joomla/application/component/controller.php Gets view instance Gets model instance Injects model into view Calls view’s display() method
  14. 16. Bad approaches for using controllers in Joomla
  15. 17. Good approaches for using controllers in Joomla
  16. 18. Bad approaches for using controllers in Joomla
  17. 19. Good approaches for using controllers in Joomla
  18. 20. MVC Model
  19. 21. A model is a hard worker!
  20. 22. You should use a model for Storing a state; Performing database tasks; Formatting data; All other data task.
  21. 23. You should not use a model for Getting request data; Rendering templates. controller & view tasks
  22. 24. A Model in Joomla
  23. 25. JModel The most unused model methods & properties. Why? $this->_db $this->_state $this->getDBO(); $this->setState($property, $value); $this->getState($property);
  24. 26. Bad approaches for using models in Joomla
  25. 27. Good approaches for using models in Joomla
  26. 28. Fat Model, Skinny Controller http://blog.astrumfutura.com/archives/373-The_M_in_MVC_Why_Models_are_Misunderstood_and_Unappreciated.html
  27. 29. MVC View
  28. 30. A view is a stylist!
  29. 31. You should use a view for Rendering templates; Rendering templates; Rendering templates.
  30. 32. You should not use a view for Database tasks; Database tasks; Database tasks. model tasks
  31. 33. A view in Joomla
  32. 34. JView lies between a model and a template View Data Template
  33. 35. You should use a Joomla view class for Getting data from models; Rearranging data (if needed); Assigning variables to templates; Rendering templates.
  34. 36. Don’t put everything you have into a view!
  35. 37. Keep your view methods small!
  36. 38. You shouldn’t use PHP in template files like this
  37. 39. You should use it like this
  38. 40. Don’t use variables in view templates other than the ones you assigned to
  39. 41. Keep your templates clear, assign all variables in view classes!
  40. 42. Add CSS and JS in the view template file … in this case they can be overwritten in a Joomla template
  41. 43. Joomla MVC revealed
  42. 44. Joomla MVC default task as it is Main component’s file request data calls Controller default task calls JController’s display() Model & view objects gets inserts Model into view calls JView’s display() gets Model data renders Template
  43. 45. The best way to figure out the Joomla framework is to dig into the code!
  44. 46. No, seriously Just dig into the code
  45. 47. After digging JController methods you can find out /libraries/joomla/application/component/controller.php How to insert other than the default model into your view class How to add another location for your model & view files How to set a default model state … and many more
  46. 48. Joomla MVC structures possible variants
  47. 52. Base controller approach
  48. 53. Base controller approach: main component file
  49. 54. Code Optimization
  50. 55. Code Optimization Write code Go! Write a bit more code Think over
  51. 56. A simple optimization Edit, publish, unpublish, save order, order up, order down, cancel, save, remove Base admin model Base admin controller Base admin view Helper classes Get ordering, save order, move, check out, check in, publish, remove The most used variables: option, document, view, controller, layout, etc. Everything that can be reused in templates
  52. 57. Code Documentation
  53. 58. Document your code http://www.phpdoc.org/ http://code.google.com/p/jsdoc-toolkit/ Every file, class, class property and method
  54. 60. Filter input, escape output! http://shiflett.org/blog/2005/feb/my-top-two-php-security-practices http://developer.joomla.org/security.html http://developer.joomla.org/security/articles-tutorials/258-preventing-sql-injections.html
  55. 61. Joomla Components design
  56. 62. We are developers, we don’t do design!
  57. 63. !!!!! We are developers, we don’t do design !!!!
  58. 64. Design principles for developers Set proper CSS classes & IDs, but leave design for template designers That’s all!
  59. 65. Thanks for coming! http://twitter.com/onesterov http://onesterov.com http://jookungfu.org http://mindk-lab.com [email_address]

×