Your SlideShare is downloading. ×
Corephpcomponentpresentation 1211425966721657-8
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Corephpcomponentpresentation 1211425966721657-8

315
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
315
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Building Components for J!1.5 As Presented by Steven Pignataro Owner of ‘corePHP’ Web Development
  • 2. What do we build for?
    • Joomla! 1.5 is built to run on PHP4 and PHP5
    • Need to keep this in mind when developing extensions.
    • Most developers are dropping support for PHP4 – some are not – you make the choice.
  • 3. Development Applications
    • ‘ corePHP’ Developers use Aptana and extended plugins
      • http://www.aptana.org
    • J!Dump – great tool to get a detailed out put for debugging.
      • http://www.joomlacode.org/gf/project/jdump
  • 4. Where do we start?
    • Joomla! 1.5 has 2 locations that we are going to be developing for:
      • Joomla! Frontend (public accessible)
      • Joomla! Backend (admin accessible)
  • 5. Libraries
    • J!1.5 provides a extensive collection of useful libraries that are easily called via jimport:
      • Jimport(‘joomla.mail.*’);
      • Jimport(‘joomla.filesystem.file’);
    • Open up libraries folder and call by the main folder / sub folder / filename.
    • Can be called like this:
      • Jimport(‘cache.cache’);
  • 6. How to grab from Request
    • Development with PHP Applications require the use of grabbing data from $_GET, $_GET, $_FILES, $_COOKIE, $_REQUEST, etc.
    • Joomla! 1.0.x we used mosGetParam(); we now pull from the JRequest function which gives us additional control:
      • JRequest::setVar()
      • JRequest::getVar()
  • 7. JRequest::GetVar()
    • How do we use it?
      • $value = $JRequest::getVar(‘value’, 0);
    • Other Methods for getting values:
      • getInt()
      • getFloat()
      • getBool()
      • getWord()
      • getCmd()
      • getString()
    • With these get strings we are guaranteeing that the values grabbed will be either an Integer or a String, or any of the other JRequest methods.
  • 8. JRequest::setVar()
    • JReqeust::setVar() methods allows you to set the values into the request.
    • Examples of use are:
      • JRequest::setVar(‘task’, ‘displayData’);
  • 9. Multilingual Support
    • Joomla! allows superior support for UTF-9 (Unicode Transformation Format-8) ecnodting. Available strings are used through JText:
      • _()
        • echo JText::_(‘ARTICLE_COUNT’);
      • sprintf() -> equivalent to PHP sprintf()
        • $value = JText::sprintf(‘ARTICLE # NOT FOUND’, 92);
        • Language INI file will have:
          • ARTICLE # NOT FOUND=Article #%d not found
      • printf() -> equivalent to PHP printf()
  • 10. Database
    • The core of Joomla! has two database drivers:
      • MySQL
      • MySQLi
    • The database can be globalized using JFactory calls:
      • $db =& JFactory::getDBO();
  • 11. How to Query the Database
    • We use setQuery() method to create the object we want to execute:
      • $db =& Jfactory::getDBO();
      • $query = ‘SELECT * FROM ‘
      • . $db->nameQuote(‘#__corephp’)
      • . ‘ WHERE ‘
      • . $db->nameQuote(‘firstname’)
      • . ‘ = ‘
      • . $db->Quote(‘Steven’)
      • $db->setQuery($query)
  • 12. How to receive results
    • With Joomla! 1.5 we have similar methods that allow us to grab results from the database. In the next few slides I will briefly discuss each one.
  • 13. Database Methods
    • loadResult(): string
    • loadResultArray( numinarray): array Array { [0] => Foo [1] => Bar }
  • 14. Database Methods (cont.)
    • loadAssoc(): array Array { [id] => 25 [name] => Steven }
    • loadAssocList( key: string=‘’): array Array { [0] => Array { [id] => 90 [name] => Steven } [1] => Array { [id] => 91 [name] => Michael } }
  • 15. Database Methods (cont.)
    • loadObject(): stdClass stdClass Object { [id] => 25 [name] => Steven }
    • loadObjectList( key: string=‘’): array Array { [0] => stdClass Object { [id] => 90 [name] => Steven } [1] => stdClass Object { [id] => 91 [name] => Michael } }
  • 16. Database Methods
    • loadRow(): array Array { [0] => Foo [1] => Bar }
    • loadRowList( key: int): array (Example: $db->loadRowList(0)); Array { [0] => Array { [id] => 90 [name] => Steven } [1] => Array { [id] => 91 [name] => Michael } }
  • 17. JRoute
    • Joomla! allows us to take advantage of SEF URI’s – in order to get these we need to use the JRoute::_() method
  • 18. How do we use JRoute?
    • With JRoute you will wrap your links like the following:
      • Echo JRoute::_(‘index.php?option=com_penguinpower&cat=1&data=6’);
    • With SEF Turned on the above link would possible produce something as follows:
      • http://www.corephp.com/index.php/component/penguinpower/1/6/
    • Not entirely SEF friendly
  • 19. Building the Route
    • To build the route – you need to create a file called router.php in the root of the component folder.
    • Two functions will be abvailable in this file:
      • BuildRoute()
      • ParseRoute()
      • Prefixed prior to above functions is the component name.
  • 20. Example of router.php
    • function penguinpowerBuildRoute(&$query) { $segments = array(); if (isset($query[‘cat’])) { $segments[] = $query[‘cat’]; unset($query[‘cat’]; if(isset($query[‘data’])) { $segments[] = $query[‘data’]; unset($query[‘data’]); } } return $segments; }
  • 21. Example Cont.
    • Function pengiunpowerParseRoute($segments) { $query = array(); if (isset($segments[0])) { $query[‘cat’] = $segments[0]; if (isset($segments[1])) { $query[‘data’] = $segments[1]; } } return $query; }
  • 22. Router.php – the truth
    • Some developers are skipping over this and not realizing the benfit this has to there component. By allowing your users to have high quality SEF links - you are allowing your users to have superior power.
    • It is important to allow your users to have proper SEF links. JRoute gives this ability and is not difficult to use if you are familiar with the previous methods of SEFing a link.
  • 23. Errors
    • J! 1.5 provides superior error messaging over the previous versions of Joomla! by using the class methods:
      • JError::raiseError()
      • JError::raiseWarning()
      • JError::raiseNotice()
  • 24. raiseError
    • JError::raiseError(‘403’, JText::_(‘You are not a penguin – go back north’));
    • Thins will provide a page with an error message with a 403 message. You can also perform other forms of errors such as 500 when an error occurs.
  • 25. raiseWarning
    • JError::raiseWarning(‘ERROR_CODE’, JText::_(‘What makes a penguin fly during a cold night?’));
    • This outputs simple messages above the mainBody of the site.
  • 26. ACL
    • Sorry – this is only an hour long – please request further information about ACL and how your site can be improved with ‘corePHP’ Community ACL.
  • 27. Security
    • Remember to start all your files with the following statement (this is one step to security – but do not stop there):
      • Defined(‘_JEXEC’) or die(‘Penguin Bites’);
  • 28. SQL Injection
    • To ensure your code is secure use the following methods to protect your data:
      • $db =& JFactory::getDBO();
      • $data = $db->QuotegetEscaped(JRequest(‘data’));
  • 29. Extension Access Control
    • There is a simple and easy way to allow access to copmonents and this can be done by doing the following example:
      • $acl =& JFactory::getACL(); $acl ->_mos_add_acl(‘com_penguinpower’, ‘manage’, ‘users’, ‘super administrator’);
  • 30. Redirects
    • Using redirects could be used when saving data / copying items / creating a new item / publishing/unpublishing or anything that you might need to redirect the user to a different location
  • 31. Redirects in use
    • $mainframe->direct(‘index.php?option=com_penguinpower’); or
    • $mainframe->redirect(‘index.php?option=com_the-zend-penguin’, ‘Why fear the Zend Penguin?’);
  • 32. What's next?
    • Well one there is a massive API – no way it can be covered in one sitting. Recommended reading:
    • Mastering Joomla! 1.5 Extension and Framework Development by James Kennard