NathanLedet Posted April 22, 2009 Share Posted April 22, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/155223-executing-a-class-inside-of-a-class/ Share on other sites More sharing options...
jackpf Posted April 22, 2009 Share Posted April 22, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155223-executing-a-class-inside-of-a-class/#findComment-816647 Share on other sites More sharing options...
Maq Posted April 22, 2009 Share Posted April 22, 2009 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(); } } Quote Link to comment https://forums.phpfreaks.com/topic/155223-executing-a-class-inside-of-a-class/#findComment-816653 Share on other sites More sharing options...
NathanLedet Posted April 22, 2009 Author Share Posted April 22, 2009 Thanks. I guess I should have mentioned that the class already extends a class: class MyController extends PluginController { } [code=php:0] I'm building plugin for a CMS. Quote Link to comment https://forums.phpfreaks.com/topic/155223-executing-a-class-inside-of-a-class/#findComment-816663 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.