SlideShare uma empresa Scribd logo
1 de 28
Baixar para ler offline
Joomla
                           Development
                         I t ’ s   E a s i e r T h a n      Y o u
                                        T h i n k




 SourceCoast Extensions               sourcecoast.com   Intro To Joomla Development
Saturday, August 6, 11                                                                1
SourceCoast
                             A l e x A n d r e a e
                         O w n e r / D e v e l o p e r

                                 JFBConnect
           Full Facebook Integration Suite for Joomla
  * Facebook Authentication
  * Facebook Page Tab / Canvas Support
  * Like, Comment, Fanbox, Recommendations & more widgets
  * Customizeable Profile Import Into
    * JomSocial, Community Builder, Kunena, K2, Agora
  * Lots more...
          Over 60 straight 5-star reviews on the JED

 SourceCoast Extensions           sourcecoast.com   Intro To Joomla Development
Saturday, August 6, 11                                                            2
Overview


                         Module Structure

                         API Overview

                         Component Structure




 SourceCoast Extensions                 sourcecoast.com   Intro To Joomla Development
Saturday, August 6, 11                                                                  3
Joomla - MVC
                         MVC(t) – Model View Controller (template)

                         Controller – Sets up environment for the display

                         Model – Data interface

                           Generally to the database, but can 'create'
                           data if necessary

                         View – Uses the model to get data to display

                         Template – Override-able display output
 SourceCoast Extensions                 sourcecoast.com     Intro To Joomla Development
Saturday, August 6, 11                                                                    4
Modules
                         Linear code execution

                         VC(t) (no real model necessary)

                         Uses a 'helper.php' file for additional function calls

                           Can be model-like, but modules don’t have DB tables

                         Files:

                           mod_<modulename>.php and .xml

                           helpers/helper.php

                           tmpl/default.php
 SourceCoast Extensions                     sourcecoast.com         Intro To Joomla Development
Saturday, August 6, 11                                                                            5
Modules - Basics
  mod_demo.xml




                          mod_demo.php



      default.php




 SourceCoast Extensions                  sourcecoast.com   Intro To Joomla Development
Saturday, August 6, 11                                                                   6
Module Helper Files
    mod_demo.php




        helper.php

                                    * Separate out Classes/Functions


                          default.php




 SourceCoast Extensions       sourcecoast.com     Intro To Joomla Development
Saturday, August 6, 11                                                          7
Modules/Component
 mod_demo.php           Interaction

                                             * Load Component’s model
                                             * Re-Use Code!


                                             helper.php




                                                      default.php



 SourceCoast Extensions    sourcecoast.com                Intro To Joomla Development
Saturday, August 6, 11                                                                  8
Joomla API
                          Overview


 SourceCoast Extensions    sourcecoast.com   Intro To Joomla Development
Saturday, August 6, 11                                                     9
Joomla API
                         http://api.joomla.com

                            Recently updated to Joomla 1.7 API - YAY!

                         Left side, select “Joomla-Platform” package

                         Bookmark, cuddle up to, and learn to love this page

                         “Classes” describes

                            JFactory – Most widely used

                            JRoute – Get URL for specific component/view/task

                         “Application” describes

                            Every other Joomla function (many inherited into JFactory)

 SourceCoast Extensions                          sourcecoast.com        Intro To Joomla Development
Saturday, August 6, 11                                                                            10
JObject
                         All Joomla classes derived from (You should too)

                         Easy getter/setter methods

                           $obj->set(‘var’, ‘value’); // Set a variable

                           $obj->get(‘var’, ‘default’); // Get a value

                           $obj->def(‘var’, ‘default’); // Set a default

                         $obj->toString(); // Great for debugging (no
                         print_r($obj) required!
 SourceCoast Extensions                   sourcecoast.com      Intro To Joomla Development
Saturday, August 6, 11                                                                   11
JUser Object
                         $user = JFactory::getUser(); // logged in user

                         $user = JUser::getInstance($id);

                         $id = UID or username

                         Once fetched, use

                           if ($user->guest)

                           $user->get('username'); // id, fullname,
                           lastvisitDate, etc

                              It’s derived from JObject!
 SourceCoast Extensions                   sourcecoast.com        Intro To Joomla Development
Saturday, August 6, 11                                                                     12
JFactory - Database
                         $dbo =& JFactory::getDBO() // Get the database handle

                         Functions described in JDatabase & JDatabaseMySQL(i)

                         $query = $dbo->getQuery(true); // New Query
                         $query->select(“id, username, email”);
                         $query->from(“#__users”);
                         $query->where(“username=”.$dbo->quote($username); // No
                         shenanigans!
                         $dbo->setQuery($query);

                         $dbo->setQuery(“SELECT id,username,email FROM #__users
                         WHERE username = “.$dbo->quote($username)); // Not as flexible

                         $user = $dbo->loadObject(); // objectList, array, arrayList, result, etc

                         Can use InsertObject function (or raw SQL) to add rows to database

 SourceCoast Extensions                         sourcecoast.com              Intro To Joomla Development
Saturday, August 6, 11                                                                                 13
URL Routing
                         JRoute

                           JRoute::_('index.php?
                           option=com_content&view=article&id=12');

                           Will determine correct SEF URL, if SEF is enabled

                           Also, SEF components (sh404, Artio, etc) override this call, so
                           it works for them too!

                         JURI

                           $uri = JFactory::getURI(); // Get current query string

                           $uri->setVar('view', 'blah'); // Add/change value

                           JRoute::_('index.php?'.$uri->getQuery()); // Create new route

 SourceCoast Extensions                      sourcecoast.com            Intro To Joomla Development
Saturday, August 6, 11                                                                            14
JApplication
                         Handle to the Application class

                         $app =& JFactory::getApplication();

                         $app->enqueueMessage('blah', 'error');

                         $app->redirect($url); // Use JRoute!

                         $app->isAdmin()

                         $app->isSite()

                         Formerly global $mainframe. Globals are bad..
 SourceCoast Extensions                   sourcecoast.com   Intro To Joomla Development
Saturday, August 6, 11                                                                15
JText
                         Text translation from language files

                         JText::_('COM_JFBCONNECT_LOGIN_MESSAGE’);

                         Searches loaded language files in last loaded order

                         Searches for first, exact, upper case version

                           If found, use translation; If not, use text directly

                         To include more language files:

                           $lang = JFactory::getLanguage(); // Get language object

                           $lang->load('com_jfbconnect'); // Add your file
 SourceCoast Extensions                     sourcecoast.com           Intro To Joomla Development
Saturday, August 6, 11                                                                          16
JRequest
                         JRequest::getVar('name', 'default', 'POST');

                         Can be risky depending on use. Preferred to
                         use the below 'sanitized' methods

                         JRequest::getInt('name', 4); // Integers only,
                         default 4

                         JRequest::getCmd('task'); // strip ./

                         JRequest::getString('name'); // No nasty
                         HTML
 SourceCoast Extensions                  sourcecoast.com     Intro To Joomla Development
Saturday, August 6, 11                                                                 17
JFilterInput
                         Clean data before using in code

                         Used to prevent SQL, XSS, and other
                         shenanigans or exploits

                         $filter =& JFilterInput::getInstance();

                         $filter->clean($var, ‘string’); //int, etc

                         Similar to (and used by) JRequest, but can be
                         used on any data, not just environment
                         variables
 SourceCoast Extensions                   sourcecoast.com      Intro To Joomla Development
Saturday, August 6, 11                                                                   18
Jsession
                         Store information volatile information for user

                         Form information on validation failure

                         Information before a redirection (to login, etc)

                         $session = JSession::getInstance();

                         $session->set('city', $cityInput); // Set now

                         $city = $session->get('city', ''); // Get later

                         $session->clear('city');
 SourceCoast Extensions                    sourcecoast.com        Intro To Joomla Development
Saturday, August 6, 11                                                                      19
Component
                         Structure


 SourceCoast Extensions    sourcecoast.com   Intro To Joomla Development
Saturday, August 6, 11                                                 20
Component
                                   Structure
                         True MVC(t) structure

                         <component_name>.php – entry-point. Determines
                         controller and calls task on it

                         controller.php – Sets up the model(s) and other data
                         structures to be used

                         /models/<model>.php – Data interface

                         /viewname/view.html.php – Uses the models to fetch
                         and setup the data for the template

                         /viewname/tmpl/default.php (or any other template file)
 SourceCoast Extensions                   sourcecoast.com        Intro To Joomla Development
Saturday, August 6, 11                                                                     21
Component Entry Point



       * /components/com_blah/blah.php
       * Purpose: setup your component - defines, includes, etc
       * Initialize the right controller for the page
       * Start executing whatever is requested
       * (This) code expects query string “task” param to be set
       * If execute called with no param, “display” will be default
 SourceCoast Extensions       sourcecoast.com     Intro To Joomla Development
Saturday, August 6, 11                                                      22
Component
                          Controllers
       Fetch model(s) for data manipulation/checks
         * $model = $this->getModel('mymodel')
         * Verify something from the model to proceed or cause a
         redirect
         * Ex. Load article, check if published, if not, redirect
       Instantiate the View
       * $view = $this->getView(‘viewName’, ‘html’);
       * Hand any data (model) to it for use
        * $view->setModel($model);
        * $view->assignRef(‘var’, $data); // var for the template
       * Tell the View to do it’s thing
        * $view->setLayout(‘templateName’);
        * $view->display();
 SourceCoast Extensions      sourcecoast.com    Intro To Joomla Development
Saturday, August 6, 11                                                    23
Controller
      (Fake) Content Example



                         Get article
                         Check if published
                         Load the view and prepare the template
                         By default, view of same name as controller will be called
                           Otherwise, use $view code from previous slide
 SourceCoast Extensions                       sourcecoast.com        Intro To Joomla Development
Saturday, August 6, 11                                                                         24
Component Model
                         The model is your database interface

                         Extends JModel

                         Has SQL queries for read or write

                         Model allows you to retrieve and manipulate
                         data simulating higher level database functions

                           Table class available for row-based read/writes

                         $this->_db is pre-set as database object
 SourceCoast Extensions                  sourcecoast.com     Intro To Joomla Development
Saturday, August 6, 11                                                                 25
Component View

                         Fetch the data needed from Model

                         Set data for template file

                           $this->assignRef('varName', $var);

                         Call the template to load



 SourceCoast Extensions                 sourcecoast.com     Intro To Joomla Development
Saturday, August 6, 11                                                                26
Component Template
                         Little/no code other than echo's

                         Should use only variables set from View

                         <?php echo $this->varName ?>

                         If followed, template overrides become simple

                           If not, life becomes a nightmare for your
                           clients

 SourceCoast Extensions                 sourcecoast.com     Intro To Joomla Development
Saturday, August 6, 11                                                                27
Plugins
                         JDocument
                            JLog
                           JForm
                           Oh My!
 SourceCoast Extensions    sourcecoast.com   Intro To Joomla Development
Saturday, August 6, 11                                                 28

Mais conteúdo relacionado

Destaque (6)

Toscana Joomla Party - Proteggiamo il nostro sito Joomla!
Toscana Joomla Party - Proteggiamo il  nostro sito Joomla!Toscana Joomla Party - Proteggiamo il  nostro sito Joomla!
Toscana Joomla Party - Proteggiamo il nostro sito Joomla!
 
Teaching Joomla the Right Way
Teaching Joomla the Right WayTeaching Joomla the Right Way
Teaching Joomla the Right Way
 
Template Layout Overrides - a beginner's guide
Template Layout Overrides - a beginner's guideTemplate Layout Overrides - a beginner's guide
Template Layout Overrides - a beginner's guide
 
Joomla Frameworks Kung Fu
Joomla Frameworks Kung FuJoomla Frameworks Kung Fu
Joomla Frameworks Kung Fu
 
Joomla development
Joomla developmentJoomla development
Joomla development
 
Joomla Extensions Kung Fu
Joomla Extensions Kung FuJoomla Extensions Kung Fu
Joomla Extensions Kung Fu
 

Semelhante a Intro to Joomla Development

Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
Ravi Mone
 
Frozen Rails Slides
Frozen Rails SlidesFrozen Rails Slides
Frozen Rails Slides
carllerche
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
The Solar Framework for PHP
The Solar Framework for PHPThe Solar Framework for PHP
The Solar Framework for PHP
ConFoo
 

Semelhante a Intro to Joomla Development (20)

Joomla Day Austin Part 4
Joomla Day Austin Part 4Joomla Day Austin Part 4
Joomla Day Austin Part 4
 
Jquery Plugin
Jquery PluginJquery Plugin
Jquery Plugin
 
Frozen Rails Slides
Frozen Rails SlidesFrozen Rails Slides
Frozen Rails Slides
 
Webpack: your final module bundler
Webpack: your final module bundlerWebpack: your final module bundler
Webpack: your final module bundler
 
Take control. write a plugin. part II
Take control. write a plugin. part IITake control. write a plugin. part II
Take control. write a plugin. part II
 
Philly Spring UG Roo Overview
Philly Spring UG Roo OverviewPhilly Spring UG Roo Overview
Philly Spring UG Roo Overview
 
Rails 101
Rails 101Rails 101
Rails 101
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
JavaScript Coding with Class
JavaScript Coding with ClassJavaScript Coding with Class
JavaScript Coding with Class
 
Starting with jQuery
Starting with jQueryStarting with jQuery
Starting with jQuery
 
Play framework
Play frameworkPlay framework
Play framework
 
Jquery
JqueryJquery
Jquery
 
What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?What is the Joomla Framework and why do we need it?
What is the Joomla Framework and why do we need it?
 
Nashville Symfony Functional Testing
Nashville Symfony Functional TestingNashville Symfony Functional Testing
Nashville Symfony Functional Testing
 
Content construction with zoo
Content construction with zooContent construction with zoo
Content construction with zoo
 
How To Build A Personal Portal On Google App Engine With Django
How To Build A Personal Portal On Google App Engine With DjangoHow To Build A Personal Portal On Google App Engine With Django
How To Build A Personal Portal On Google App Engine With Django
 
The Solar Framework for PHP
The Solar Framework for PHPThe Solar Framework for PHP
The Solar Framework for PHP
 
Advance jquery-plugin
Advance jquery-pluginAdvance jquery-plugin
Advance jquery-plugin
 
jQuery Tips Tricks Trivia
jQuery Tips Tricks TriviajQuery Tips Tricks Trivia
jQuery Tips Tricks Trivia
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 

Intro to Joomla Development

  • 1. Joomla Development I t ’ s E a s i e r T h a n Y o u T h i n k SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 1
  • 2. SourceCoast A l e x A n d r e a e O w n e r / D e v e l o p e r JFBConnect Full Facebook Integration Suite for Joomla * Facebook Authentication * Facebook Page Tab / Canvas Support * Like, Comment, Fanbox, Recommendations & more widgets * Customizeable Profile Import Into * JomSocial, Community Builder, Kunena, K2, Agora * Lots more... Over 60 straight 5-star reviews on the JED SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 2
  • 3. Overview Module Structure API Overview Component Structure SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 3
  • 4. Joomla - MVC MVC(t) – Model View Controller (template) Controller – Sets up environment for the display Model – Data interface Generally to the database, but can 'create' data if necessary View – Uses the model to get data to display Template – Override-able display output SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 4
  • 5. Modules Linear code execution VC(t) (no real model necessary) Uses a 'helper.php' file for additional function calls Can be model-like, but modules don’t have DB tables Files: mod_<modulename>.php and .xml helpers/helper.php tmpl/default.php SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 5
  • 6. Modules - Basics mod_demo.xml mod_demo.php default.php SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 6
  • 7. Module Helper Files mod_demo.php helper.php * Separate out Classes/Functions default.php SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 7
  • 8. Modules/Component mod_demo.php Interaction * Load Component’s model * Re-Use Code! helper.php default.php SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 8
  • 9. Joomla API Overview SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 9
  • 10. Joomla API http://api.joomla.com Recently updated to Joomla 1.7 API - YAY! Left side, select “Joomla-Platform” package Bookmark, cuddle up to, and learn to love this page “Classes” describes JFactory – Most widely used JRoute – Get URL for specific component/view/task “Application” describes Every other Joomla function (many inherited into JFactory) SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 10
  • 11. JObject All Joomla classes derived from (You should too) Easy getter/setter methods $obj->set(‘var’, ‘value’); // Set a variable $obj->get(‘var’, ‘default’); // Get a value $obj->def(‘var’, ‘default’); // Set a default $obj->toString(); // Great for debugging (no print_r($obj) required! SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 11
  • 12. JUser Object $user = JFactory::getUser(); // logged in user $user = JUser::getInstance($id); $id = UID or username Once fetched, use if ($user->guest) $user->get('username'); // id, fullname, lastvisitDate, etc It’s derived from JObject! SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 12
  • 13. JFactory - Database $dbo =& JFactory::getDBO() // Get the database handle Functions described in JDatabase & JDatabaseMySQL(i) $query = $dbo->getQuery(true); // New Query $query->select(“id, username, email”); $query->from(“#__users”); $query->where(“username=”.$dbo->quote($username); // No shenanigans! $dbo->setQuery($query); $dbo->setQuery(“SELECT id,username,email FROM #__users WHERE username = “.$dbo->quote($username)); // Not as flexible $user = $dbo->loadObject(); // objectList, array, arrayList, result, etc Can use InsertObject function (or raw SQL) to add rows to database SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 13
  • 14. URL Routing JRoute JRoute::_('index.php? option=com_content&view=article&id=12'); Will determine correct SEF URL, if SEF is enabled Also, SEF components (sh404, Artio, etc) override this call, so it works for them too! JURI $uri = JFactory::getURI(); // Get current query string $uri->setVar('view', 'blah'); // Add/change value JRoute::_('index.php?'.$uri->getQuery()); // Create new route SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 14
  • 15. JApplication Handle to the Application class $app =& JFactory::getApplication(); $app->enqueueMessage('blah', 'error'); $app->redirect($url); // Use JRoute! $app->isAdmin() $app->isSite() Formerly global $mainframe. Globals are bad.. SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 15
  • 16. JText Text translation from language files JText::_('COM_JFBCONNECT_LOGIN_MESSAGE’); Searches loaded language files in last loaded order Searches for first, exact, upper case version If found, use translation; If not, use text directly To include more language files: $lang = JFactory::getLanguage(); // Get language object $lang->load('com_jfbconnect'); // Add your file SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 16
  • 17. JRequest JRequest::getVar('name', 'default', 'POST'); Can be risky depending on use. Preferred to use the below 'sanitized' methods JRequest::getInt('name', 4); // Integers only, default 4 JRequest::getCmd('task'); // strip ./ JRequest::getString('name'); // No nasty HTML SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 17
  • 18. JFilterInput Clean data before using in code Used to prevent SQL, XSS, and other shenanigans or exploits $filter =& JFilterInput::getInstance(); $filter->clean($var, ‘string’); //int, etc Similar to (and used by) JRequest, but can be used on any data, not just environment variables SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 18
  • 19. Jsession Store information volatile information for user Form information on validation failure Information before a redirection (to login, etc) $session = JSession::getInstance(); $session->set('city', $cityInput); // Set now $city = $session->get('city', ''); // Get later $session->clear('city'); SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 19
  • 20. Component Structure SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 20
  • 21. Component Structure True MVC(t) structure <component_name>.php – entry-point. Determines controller and calls task on it controller.php – Sets up the model(s) and other data structures to be used /models/<model>.php – Data interface /viewname/view.html.php – Uses the models to fetch and setup the data for the template /viewname/tmpl/default.php (or any other template file) SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 21
  • 22. Component Entry Point * /components/com_blah/blah.php * Purpose: setup your component - defines, includes, etc * Initialize the right controller for the page * Start executing whatever is requested * (This) code expects query string “task” param to be set * If execute called with no param, “display” will be default SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 22
  • 23. Component Controllers Fetch model(s) for data manipulation/checks * $model = $this->getModel('mymodel') * Verify something from the model to proceed or cause a redirect * Ex. Load article, check if published, if not, redirect Instantiate the View * $view = $this->getView(‘viewName’, ‘html’); * Hand any data (model) to it for use * $view->setModel($model); * $view->assignRef(‘var’, $data); // var for the template * Tell the View to do it’s thing * $view->setLayout(‘templateName’); * $view->display(); SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 23
  • 24. Controller (Fake) Content Example Get article Check if published Load the view and prepare the template By default, view of same name as controller will be called Otherwise, use $view code from previous slide SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 24
  • 25. Component Model The model is your database interface Extends JModel Has SQL queries for read or write Model allows you to retrieve and manipulate data simulating higher level database functions Table class available for row-based read/writes $this->_db is pre-set as database object SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 25
  • 26. Component View Fetch the data needed from Model Set data for template file $this->assignRef('varName', $var); Call the template to load SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 26
  • 27. Component Template Little/no code other than echo's Should use only variables set from View <?php echo $this->varName ?> If followed, template overrides become simple If not, life becomes a nightmare for your clients SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 27
  • 28. Plugins JDocument JLog JForm Oh My! SourceCoast Extensions sourcecoast.com Intro To Joomla Development Saturday, August 6, 11 28