Taylor J
Well-known member
I'm attempting to set an sql field on an entity to the location of an image inside of XF's data dir at the time when the creation/save process happens but I'm not quite sure how to approach this.
I am able to get the file saved with the proper filename and in the proper place (data://taylorj_blogs/blog_header_image/filenamehere.jpg) where filename is the id of the entity that is/was created.
I've tried placing my code in my saveProcess method as seen below
but since the entity hasn't been created/saved yet it doesn't have an actual "blog_id" yet and every path is set to data://taylorj_blogs/blog_header_image/0.jpg.
To save the image with the actual blog_id I have my code to save the image in the actionSave method below
but it doesn't feel or seem right to try and attempt to update a entity's sql fields here in this area.
Am I even headed in the right direction with this? I feel like i'm overcomplicating it.
I am able to get the file saved with the proper filename and in the proper place (data://taylorj_blogs/blog_header_image/filenamehere.jpg) where filename is the id of the entity that is/was created.
I've tried placing my code in my saveProcess method as seen below
PHP:
protected function blogSaveProcess(\TaylorJ\Blogs\Entity\Blog $blog)
{
$input = $this->filter([
'blog_title' => 'str',
'blog_description' => 'str',
]);
$form = $this->formAction();
$form->basicEntitySave($blog, $input);
return $form;
}
To save the image with the actual blog_id I have my code to save the image in the actionSave method below
PHP:
public function actionSave(ParameterBag $params)
{
if ($params->blog_id)
{
$blog = $this->assertBlogExists($params->blog_id);
}
else
{
$blog = $this->em()->create('TaylorJ\Blogs:Blog');
}
$this->blogSaveProcess($blog)->run();
if ($upload = $this->request->getFile('upload', false, false)) {
$this->getBlogRepo()->setBlogHeaderImagePath($blog->blog_id, $upload);
}
return $this->redirect($this->buildLink('blogs'));
}
Am I even headed in the right direction with this? I feel like i'm overcomplicating it.