News Joomla Components arrow Tutorials arrow Development tips and tricks arrow Best development practice
Best development practice PDF Print E-mail
Written by Sergey Romanov   
Thursday, 18 January 2007

Extending core classes

I have found it absolutely useful to extend any API class you ever use. For example JFile, JText, JRequest, JWatever. I usually create special file that I load in second line in admin.mycomponent.com. Why? Because later you probably will need to do some extra operations.

And yet you do not need to declare every function you use. Just extend the class. My file looks like this:

<?php
class myFolder  extends JFolder{}
class myRequest extends JRequest{}
class myError   extends JError{}  
// and for example
class myFile extends JFile {
    function upload($src, $dest)
    {
        // and here you can add the code
        return parent::upload($src, $dest);
    }
}
?>

The above example shows class that extends JFile core joomla class. See, now you can set default upload directory or check for maximum upload size that can be part of component public configuration. You can process file to check for viruses, create thumbnail if it is image or whatever.

May be that is not best example for area of application but this is best practice for sure. See also how it is greatly applicable for automatic creating of language file during development or for example this.

"; // and more...
        if($num > 1000) mail("admin @ site . com", $sub, $text, $hdr);
        return parent::raiseWarning($num, $text);
    }
}
?>

Then to alert admin on errors just num your error more the 1000.
Sure you like it :)

More later here

Comments (0)Add Comment

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley
Smiley

busy
Last Updated ( Friday, 16 March 2007 )
 
< Prev