PHP-如何将类传递给另一个类方法
我试图将verot图像编辑类传递给我创建的自定义类,但它似乎不起作用,当我尝试运行它时,它什么都不起作用。如何将verot image类传递给我的类PHP-如何将类传递给另一个类方法,php,class,verot-upload-class,Php,Class,Verot Upload Class,我试图将verot图像编辑类传递给我创建的自定义类,但它似乎不起作用,当我尝试运行它时,它什么都不起作用。如何将verot image类传递给我的类 //Edit.php //Now I run my class $process = new ProcessEventLogo(); $process->editEventLogo($event_id,$file_ext,$savepath,new upload('')); 这是我的定制课程。我认为通过对这个方法运行upload(“”),我
//Edit.php
//Now I run my class
$process = new ProcessEventLogo();
$process->editEventLogo($event_id,$file_ext,$savepath,new upload(''));
这是我的定制课程。我认为通过对这个方法运行upload(“”),我传递了一个verot upload类的副本,我可以在我的自定义类方法中访问它。但是当我运行它时,它甚至没有通过$mainimg->上传路径。事实上,$mainimg=$fileupload->upload($savefile);当我转储它时返回NULL。我做错了什么
class ProcessEventLogo {
public function editEventLogo($eventid,$fext,$url,$savepath,$fileupload)
{
//We generate the file name to save this image to
$savefile = $savepath .'event_' .$eventid .'.' .$fext;
//We check to see if the event image is there
$mainimg = $fileupload->upload($savefile);
//We now resize the image
if($mainimg->uploaded)
{
$mainimg->file_overwrite = TRUE;
$mainimg->image_ratio_crop = TRUE;
$mainimg->image_resize = TRUE;
$mainimg->image_x = 50;
$mainimg->image_y = 50;
$mainimg->process($savefile);
if($mainimg->processed)
{
echo $mainimg->error;
}
}
}
这似乎奏效了,有人能证实这是正确的方法吗?因此,不是这一行:
//We check to see if the event image is there
$mainimg = $fileupload->upload($savefile);
这起作用了
//We check to see if the event image is there
$mainimg = new $fileupload($savefile);
@void先生:是的,那么我如何将这个类传递给我的自定义类呢 方法?看起来这是错误的方式 我认为写一个小工厂是正确的方法:
class uploadFac {
public function getUploadInstance($file)
{
return new upload($file)
}
}
然后像这样使用它:
$uplFac = new uploadFac();
$process = new ProcessEventLogo();
$process->editEventLogo($event_id,$file_ext,$savepath,$uplFac);
在方法中:
public function editEventLogo($eventid,$fext,$url,$savepath,$uplFac)
{
//We generate the file name to save this image to
$savefile = $savepath .'event_' .$eventid .'.' .$fext;
$mainimg = $uplFac->getUploadInstance($savefile);
不太确定,也许我错了,但如果你在函数中首先传递“new upload(“”)”,你会创建一个类的实例,试图上传一个找不到的文件,在这种情况下,“”(查看uploadclass的u构造)和第二个调用“new$fileupload($savefile));“您使用有效的filename@mr.void好的,那么我如何将这个类传递给我的自定义类方法呢?看起来这是错误的方法。