Quantcast
Channel:
Viewing all articles
Browse latest Browse all 4235

how to get image object?

$
0
0

Hi,
i am trying to get and manipulate an image object (SS3.1) within a function.

But $image = Image::get()->where("\"Name\" LIKE '%$filename%'"); wii return a DataList and not the image object itself.
Can anybody give a hint? Here is the complete function:

public static function imageByFilename(&$obj, $val, $record){
$filename = strtolower(Convert::raw2sql($val));
$image = Image::get()->where("LOWER(\"Name\") LIKE '%$filename%'");
if($filename && $image){
if($image->exists()){
echo "IMAGE: ";echo "<pre>".var_dump($image)."</pre>"; die();
$image->ClassName = self::get_product_class_name().'_Image';
$image->write();
return $image;
}
}
return null;
}

Greetings from germany, Carsten.

EDIT:

I have inserted a foreach loop and now i get the image object. But i still get a server error at $image->write(); in imageByFilename().

What i want to do is: 1) write the ProduktbildID from my has_one relation to the Produkte.ProduktbildID field and 2.) alter the ClassName in File from Image to Produkte_Image.

Here is some code from my "class ProdukteCsvBulkLoader extends CsvBulkLoader"

public $relationCallbacks = array(
    'File.Name' => array(
'relationname' => 'Image',
'callback' => 'imageByFilename'
)
);

   public static function imageByFilename(&$obj, $val, $record){
      $filename = strtolower(Convert::raw2sql($val));
      $images = Image::get()->where("LOWER(\"Name\") LIKE '%$filename%'");
      
      foreach($images AS $imageout) {
         $image = $imageout;
      }
      
      if($filename && $image){
         if($image->exists()){
            $image->ClassName = self::get_product_class_name().'_Image';
            $image->write();
            return $image;
         }
      }
      return null;
   }


Posted to: how to get image object? | Show Thread | Post Reply


Viewing all articles
Browse latest Browse all 4235

Trending Articles