Jump to content

Executing a class inside of a class


NathanLedet

Recommended Posts

Still learning a bit about OOP...

 

If I have a class that runs and process all of my form submissions, can I execute a function that generates a thumbnail when someone uploads an image?

 

For example...

class MyController
{
   function upload_image()
   {
      //queries and stuff to go here to get all of the form data
     
      //code to process image:
      require_once('Thumbnail.class.php');
      $tn = new Thumbnail(200,200);
      $tn->loadFile("filename.jpg");
      $tn->buildThumb();
      
   }
}

 

and of course, my Thumbnail.class.php would contain all of the functions to generate the thumbnail.

 

Is this method doable? or should I consider putting all of my thumbnail functions in my already existing "MyController" class?

 

any other suggestions? Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/155223-executing-a-class-inside-of-a-class/
Share on other sites

Well yeah, it's easily doable, you just call it like you would normally.

 

If you're only going to use the other class within this one, then I would personally combine the two. It makes no difference, it just depends on how you like to structure your code.

You can extend the class you want to use and call the functions with parent.

 

class MyController extends Thumbnail
{
   function upload_image()
   {

      //queries and stuff to go here to get all of the form data
      parent::Thumbnail(200,200);
      parent::loadFile("filename.jpg");
      parent::buildThumb();
      
   }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.