View Single Post
  #1  
Old 07-28-2019, 01:13 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 446
 

Default Can't save image

I am writing a module with new model with image, and page for editing the entities.
So, the first step was combine https://devs.x-cart.com/basics/model_editing_page.html (ModelEditingDemo) and https://devs.x-cart.com/basics/understanding_models.html (RepoDemo). As I don't want to have two modules, I put the only php file from RepoDemo inside the ModelEditingDemo tree. I change all namespaces, "product" to
"testentity", etc. So far everything works.


The next step : add a property with image. There is an example https://devs.x-cart.com/basics/using_images_widget.html but there are some differences.


We don't have to decorate TestEntity class, it suffices to add the image and getter/setter function in Model/TestEntity.php. So I put these lines
Code:
/** * @OneToMany (targetEntity="XLite\Module\XCExample\ModelEditingDemo\Model\I mage\TestEntity\SecondaryImage", mappedBy="testentity", cascade={"all"}) * @OrderBy ({"orderby" = "ASC"}) */ protected $secondaryImages;
and
Code:
public function __construct(array $data = array()) { parent::__construct($data); $this->secondaryImages = new \Doctrine\Common\Collections\ArrayCollectio n(); } public function getSecondaryImages() { return $this->secondaryImages; } public function addSecondaryImages($image) { $this->secondaryImages[] = $image; return $this; }


I also create the class for images, Model/Image/TestEntity/SecondaryImage.php
(well, the images aren't secondary, but the more changes I make, the more places I could make mistakes, so...) just as in the image widget example, with a modification

(aside from the namespace)
Code:
/** * @ManyToOne (targetEntity="\XLite\Module\XCExample\ModelEditingDemo\Model \TestEntity", inversedBy="secondary_images") * @JoinColumn (name="testentity_id", referencedColumnName="id") */ protected $testentity;
(Note that TestEntity entities have id's, not testentity_id's).


So far things look fine, in the database, we get a table testentity_secondary_images.


Next, I make Model/Repo/Image/TestEntity/SecondaryImage.php
with
Code:
public function getStorageName() { return 'testentity'; }
Here things don't go well, as I don't see the directory xcart/image/testentity_getting created. But let's go on. What we haven't done yet (as far as the admin page is concerned) in xcart kb image widget example are DTO decoration and FormModel modification. Now, the other property of TestEntity (text) doesn't use DTO, and we don't have appropriate DTO class to modify, so presumably we don't need DTO class. Or am I wrong here?


In any case, as to FormModel, again, as we are using View/Model/TestEntity.php to output detail form, it is this file to modify, and I

put
Code:
'image' => array( self::SCHEMA_CLASS => 'XLite\View\FormField\FileUploader\Image', self::SCHEMA_LABEL => 'icon', self::SCHEMA_REQUIRED => false, ),
.


With these modifications (and some other obvious ones) I have entity editing form with image uploader, but the images are never saved. What am I doing wrong?
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote