39
How to create a Joomla component from scratch Tim Plummer @bfsurvey Presented at Sydney JUG 12/06/2012

How to create a joomla component from scratch

Embed Size (px)

DESCRIPTION

In this presentation, Tim Plummer shows you how you can create your own Joomla component by forking Hello World, then adding some improvements to make it more like a typical third party Joomla extension. Files and code used in this presentation will be available for download.

Citation preview

Page 1: How to create a joomla component from scratch

How to create a Joomla component from scratch

Tim Plummer

@bfsurvey

Presented at Sydney JUG 12/06/2012

Page 2: How to create a joomla component from scratch

About me

• I’ve developed over 24 Joomla extensions including…

• Member of bug squad

• Contributed code to Joomla core

• Convenor of the Sydney JUG (2012)

• Co-organiser of Sydney JoomlaDay

Tim Plummer @bfsurvey

Page 3: How to create a joomla component from scratch

My Joomla Development Story

Page 4: How to create a joomla component from scratch

What is a component?

Page 5: How to create a joomla component from scratch

What is a module?

Page 6: How to create a joomla component from scratch

What is a plugin?

Page 7: How to create a joomla component from scratch

Can we make a component in an hour?

Yes (if we cheat)

Page 8: How to create a joomla component from scratch

Tools you need

• Web Server & PHP & MySQL (XAMPP)

• Text editor or IDE (Textpad /

Notepad++ or Eclipse / Netbeans)

• Web browser (Firefox with firebug)

Page 9: How to create a joomla component from scratch

What license?

• GNU GPL (if you want to be listed on the JED)

• Free as in “Freedom” not free as in “Free Beer”

Page 10: How to create a joomla component from scratch

Set Error Reporting to Maximum

Page 11: How to create a joomla component from scratch

Security

Never EVER trust your user

ALWAYS sanitise user input!

Page 12: How to create a joomla component from scratch

Let’s fork com_helloworld

Page 13: How to create a joomla component from scratch

File Structure

Page 14: How to create a joomla component from scratch

Demo time…

Page 15: How to create a joomla component from scratch

Batch rename files

@echo off

setlocal enabledelayedexpansion

for /R %%j in (*.*) do (

set filename=%%~nj

set filename=!filename:helloworld=sjug!

if not !filename!==%%~nj ren %%j !filename!%%~xj

)

Page 16: How to create a joomla component from scratch

Find and replace text

com_helloworld com_sjug HelloWorld Sjug COM_HELLOWORLD COM_SJUG helloworld sjug HELLOWORLD SJUG Hello World Sjug hello sjug Hello Sjug World Sjug

Page 17: How to create a joomla component from scratch

grepWin (free tool – windows only)

Page 18: How to create a joomla component from scratch

Xml file

• Change date, author, version etc

Page 19: How to create a joomla component from scratch

Zip it up

• I like 7-zip (http://www.7-zip.org/)

Page 20: How to create a joomla component from scratch

Now let’s install it

Page 21: How to create a joomla component from scratch

Now let’s try it

Page 22: How to create a joomla component from scratch

Demo time…

Page 23: How to create a joomla component from scratch

Add more fields to the form

Page 24: How to create a joomla component from scratch

Add more fields to the form

/administrator/components/com_sjug/models/forms/sjug.xml

Page 25: How to create a joomla component from scratch

Add more fields to the form

/administrator/language/en-GB/en-GB.com_sjug.ini

Page 26: How to create a joomla component from scratch

Add more fields to the form

Use phpMyAdmin

You should also add these fields to /administrator/components/com_sjug/sql/install.mysql.utf8.sql

Page 27: How to create a joomla component from scratch

Adding toolbar buttons

• http://docs.joomla.org/JToolBarHelper

JToolBarHelper::publish(‘sjugs.publish', 'JTOOLBAR_PUBLISH', true);

JToolBarHelper::unpublish(‘sjugs.unpublish', 'JTOOLBAR_UNPUBLISH', true);

JToolBarHelper::archiveList(‘sjugs.archive');

Page 28: How to create a joomla component from scratch

Add published column to list view

Page 29: How to create a joomla component from scratch

Add published column to list view

/administrator/components/com_sjug/views/sjugs/tmpl/default_head.php

<th width="5%">

<?php echo JText::_('JSTATUS'); ?>

</th>

/administrator/components/com_sjug/views/sjugs/tmpl/default_body.php

<td>

<?php echo JHtml::_('jgrid.published', $item->published, $i, ‘sjugs.', '', 'cb', $item->publish_up, $item->publish_down); ?>

</td>

/administrator/components/com_sjug/models/sjugs.php

$query->select('id,greeting,published,publish_up,publish_down');

/administrator/components/com_sjug/views/sjugs/tmpl/default_foot.php

<td colspan="4">

Page 30: How to create a joomla component from scratch

Fix menu icon

/media/com_sjug/images/tux-16x16.png

Page 31: How to create a joomla component from scratch

Fix Toolbar Image

/media/com_sjug/images/tux-48x48.png

Page 32: How to create a joomla component from scratch

Add link to title in list view

/administrator/components/com_sjug/views/sjugs/tmpl/default_body.php

Page 33: How to create a joomla component from scratch

Status Filter

/administrator/components/com_sjug/views/sjugs/tmpl/default.php

/administrator/components/com_sjug/views/sjugs/view.html.php

Page 34: How to create a joomla component from scratch

Status Filter

/administrator/components/com_sjug/models/sjugs.php

Page 35: How to create a joomla component from scratch

Change delete to trash

/administrator/components/com_sjug/views/sjugs/view.html.php

Page 36: How to create a joomla component from scratch

Now it looks like a Joomla Component

Page 37: How to create a joomla component from scratch

Now you are ready to start creating your own components

Page 38: How to create a joomla component from scratch

Questions?

Page 39: How to create a joomla component from scratch

Tim Plummer

@bfsurvey

[email protected]