| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Can't save image | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
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:
Code:
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:
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:
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:
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 |
|||||||
#2
|
|||||||
|
|||||||
Re: Can't save image
OK, I think I have solved this.
As I am imitating the model "Category" I should be putting only one image for my entity (and this is enough for my purpose). So here is how it goes : in my module, aside from Main.php, I have 7 php files and one twig file. The entity is called "Author", module is "Librairie" and vendor name is EdB. The files are: Controller file Controller/Admin/AuthorEdit.php Page view file View/Page/Admin/AuthorEdit.php which calls the twig file the twig file page/myentity_edit/body.twig which calls the input forms, which is View/Model/Author.php View/Form/Model/Author.php and the definition of entities Model/Author.php Model/Image/Author/Image.php and the path to the image storage Model/Repo/Image/Author/Image.php The relevant part of the codes are the definition of image property and getter and setter in Model/Author.php Code:
Code:
and the image uploader definition in View/Model/Author.php Code:
Code:
I hope this helps people having similar issues.
__________________
X-cart 5.2.12, php 5.6 Ed from Grenoble, France |
|||||||
|
#3
|
|||||||
|
|||||||
Re: Can't save image
I realized that I missed the file Model/Repo/Author.php , but things do work without it anyway. Anyhow, for anyone who might care, attached is the complete module.
__________________
X-cart 5.2.12, php 5.6 Ed from Grenoble, France |
|||||||
|
|
|||
X-Cart forums © 2001-2020
|