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.

Building a Joomla Module

1,079 views

Published on

In this presentation, I cover how to build a custom Joomla module. It includes a link so you can download the finished module.

Published in: Internet
  • Very Good tutorial for building a Joomla Module, here's a tutorial for installing a Joomla Module at: https://www.cloudways.com/blog/install-joomla-module/ I hope you guys will like it too. Thanks
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Building a Joomla Module

  1. 1. Building a Joomla Module Cory Webb Joomla Day Chicago 2017 CoryWebbMedia.com CWExtensions.com @corywebb
  2. 2. Who is this guy? • Joomla developer since 2003 (Mambo) • Owner Cory Webb Media & CWExtensions.com • Course creator for OSTraining.com • Author of Beginning Joomla Web Site Development (Wrox, 2009)
  3. 3. Agenda • Build a module to display a Joomla article • Hello World • Database query • Display the article • Add a helper file • Add a template layout
  4. 4. Get the Module https://cwextensions.com/jday-chicago
  5. 5. Build the Module • Create folder named mod_article_display • Add 2 files: 
 mod_article_display.php
 mod_article_display.xml • Add language files: 
 en-GB.mod_article_display.ini
 en-GB.mod_article_display.sys.ini • Discover install
  6. 6. Hello World • Display “Hello World” in the module output • Edit mod_article_display.php
 
 defined(‘_JEXEC’) or die;
 echo ‘<h3>Hello world!</h3>’; • Publish the module
  7. 7. Database Query • Get the article ID
 
 $article_id = $params->get(‘article_id’); • Create the query
 
 $db = JFactory::getDbo();
 $query = $db->getQuery(true);
 $query->select(‘*’)->from(‘#__content’)->where(‘id = ‘ . $article_id);
 $db->setQuery($query); • Load the article
 
 $article = $db->loadObject();
  8. 8. Display the article • Get a link to the article with ContentHelperRoute
 
 JLoader::register(‘ContentHelperRoute', JPATH_SITE . '/components/com_content/ helpers/route.php');
 $article->slug = $article->id . ‘:’ . $article->alias;
 $article->link = JRoute::_(
 ContentHelperRoute::getArticleRoute(
 $article->slug, $article->catid, $article->language
 )
 ); • Display the article
 
 echo ‘<h3><a href=“’ . $article->link . ‘“>’ . $article->title . ‘</a></h3>’;
 echo ‘<div class=“article-display-article”>’ . $article->introtext . ‘</div>’;
 echo ‘<p><a href=“‘ . $article->link . ‘“ class=“read-more”>Read More</a></p>’;
  9. 9. Add a Helper File • helper.php
 
 class ModArticleDisplayHelper {…} • Load the helper class
 
 JLoader::register('ModArticleDisplayHelper', __DIR__ . ‘/helper.php'); • Move logic to helper
 
 $article = ModArticleDisplayHelper::getArticle($params);
  10. 10. Add a Template Layout • tmpl/default.php • Load the template
 
 require JModuleHelper::getLayoutPath('mod_article_display', $params->get('layout', ‘default'));
  11. 11. Questions/Comments

×