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:
public function __construct(array $data = array()) 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:
'image' => array( 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? |
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:
namespace XLite\Module\EdB\Librairie\Model\Image\Author; and the image uploader definition in View/Model/Author.php Code:
'image' => array( Code:
namespace XLite\Module\EdB\Librairie\Model\Repo\Image\Author; I hope this helps people having similar issues. |
Re: Can't save image
1 Attachment(s)
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.
|
All times are GMT -8. The time now is 02:25 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.