Twitter
Error
  • Article Not Found
Fri
25
Apr
'08
PDF
Print
Send
 
Hits (2483) | Comments (1) | Favorited (0) | Votes (0)

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:

  1. <?php
  2. class myFolder extends JFolder{}
  3. class myRequest extends JRequest{}
  4. class myError extends JError{}
  5. // and for example
  6. class myFile extends JFile {
  7. function upload($src, $dest)
  8. {
  9. // and here you can add the code
  10. return parent::upload($src, $dest);
  11. }
  12. }
  13. ?>

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.

  1. <?php
  2. class myError extends JError{
  3. function raiseWarning($num, $text)
  4. {
  5. // Log Error
  6. error_log($text, 3, "error.log");
  7. //alert admin
  8. $sub = "Important Error";
  9. // extend text. More vlues can be added like user ID id
  10. // loged in, request url or any other that can help.
  11. $text .= "User IP: ".$_SERVER['REMOTE_ADDR']; // and more...
  12. $hdr = "From: Robot <robot @ sire . com>"; // and more...
  13. if($num > 1000) mail("admin @ site . com", $sub, $text, $hdr);
  14. return parent::raiseWarning($num, $text);
  15. }
  16. }
  17. ?>

Then to alert admin on errors just num your error more the 1000.

Sure you like it :)



Comments
avatar
Quote
- -
Written by fcm.yeah on 01 December 2008

i have a problem ... i want to view user list with full infomation.when profile.php can show addition infomatio, though code is same in field alias.

 foreach( $this->card_extended_fields as $field ){
            unset($some_date);
            $params = new JParameter($field->params);
            if( !$params->get('show_at_userlist_card') || !trim( $user->{'field_'.$field->alias} )){ continue; }
            
            ?>
            <tr>
            <td nowrap="nowrap">
              <b><?php echo $field->title ?>:</b>
            </td>
            <td><?php
              if( in_array( $field->type, array('date', 'calendar')) ){
                $some_date = new JDate( $user->{'field_'.$field->alias} );
                echo $some_date->toFormat(JText::_('DATE_FORMAT_LC'));
              } else {
                echo $user->{'field_'.$field->alias};
              }

            ?></td>
            </tr>
            <?php
          }        

  ?>

 

thanks !

-
Add New Comment
Name:
Email:
Comment:
Attachment
Hide Comment
Security code:
Enter text as you see on image
 
 
What is best way for Download/Installation MightyExtensions?
 


Member Area



Member Activity

We have 2022 guests and 7 members online


MightyTemplate - Professional Joomla Templates