Hijacking controllers and views in Joomla
Table of Contents for Paceville.com - The Coding
- Customizing Joomla 1.5
- Adding AJAX to Joomla 1.5 with jQuery
- Adding custom columns/fields to Joomla article, section and user
- Hardening the Joomla hacks
- Hijacking controllers and views in Joomla
- Search Engine Friendly urls in Joomla
- Facebook style information box with jQuery
- Image manipulation and watermarking in PHP with GD2
- Joomla! 1.5x Customization – Book review and general Joomla discussion
- Mailing with Joomla’s JMail
- Lost Flirts – a Joomla 1.5 component from scratch
- Facebook style photo tagging with jQuery, Ajax and Joomla
- Controlling form tabbing with jQuery
- Facebook style chat with jQuery and Joomla
- JQuery Joomla chat, adding online/offline and friendlist
Through our plgCommunityExt class what was described in the first article in this series it’s very easy to use controllers and views anywhere you like.
Below is an example of taking advantage of a view and controller of JomSocial:
function getComCtrl($file, $cls){
require_once( JPATH_BASE . DS . 'components' . DS . 'com_community' . DS . 'controllers' . DS . "$file.php");
return new $cls();
}
function getComView($folder, $cls){
require_once( JPATH_BASE . DS . 'components' . DS . 'com_community' . DS . 'views' . DS . $folder . DS . "view.html.php");
return new $cls();
}
function fetchProfile(){
$profile = $this->getComCtrl('profile', 'CommunityProfileController')->profile(true);
return $this->getComView('profile', 'CommunityViewProfile')->_getProfileHTML($profile->profile);
}
The first two methods are simply helpers to load the chosen file and then instantiate and return the class.
The final fetchProfile will then let us fetch a user’s profile page wherever we want.
Taking advantage of already existing model classes is another good tip, just like this:
function getFriends(){
$fm = CFactory::getModel('friends');
return $fm->getFriends( $this->getUser()->id );
}
Here we simply load the model since we have access to all the JomSocial libraries and helpers (remember, we are loaded last in the stack).