• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Intro to Joomla Development
 

Intro to Joomla Development

on

  • 3,445 views

This session was presented at Joomla Day Chicago as an introduction to Joomla Development in Joomla 1.6 and beyond.

This session was presented at Joomla Day Chicago as an introduction to Joomla Development in Joomla 1.6 and beyond.

http://www.sourcecoast.com/

Statistics

Views

Total Views
3,445
Views on SlideShare
3,259
Embed Views
186

Actions

Likes
1
Downloads
145
Comments
0

2 Embeds 186

http://joomladaychicago.com 176
http://www.joomladaychicago.com 10

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Intro to Joomla Development Intro to Joomla Development Presentation Transcript

    • 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 DevelopmentSaturday, 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 DevelopmentSaturday, August 6, 11 2
    • Overview Module Structure API Overview Component Structure SourceCoast Extensions sourcecoast.com Intro To Joomla DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, August 6, 11 5
    • Modules - Basics mod_demo.xml mod_demo.php default.php SourceCoast Extensions sourcecoast.com Intro To Joomla DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, August 6, 11 8
    • Joomla API Overview SourceCoast Extensions sourcecoast.com Intro To Joomla DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, August 6, 11 19
    • Component Structure SourceCoast Extensions sourcecoast.com Intro To Joomla DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, 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 DevelopmentSaturday, August 6, 11 26
    • Component Template Little/no code other than echos 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 DevelopmentSaturday, August 6, 11 27
    • Plugins JDocument JLog JForm Oh My! SourceCoast Extensions sourcecoast.com Intro To Joomla DevelopmentSaturday, August 6, 11 28