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
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.

Link to comment
Share on other sites

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();
      
   }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.