Question

I have a question: I need upload an image (in form) and add path to it (eg: /uploads/0/20131010_logo.png) to database (as value of image field), how can i do that? FileStore already configured

my form (field previewIMG):

$form = $this->add('Form',null,'addPostForm');
$form->setModel('Post', array('title','slug', 'previewIMG', 'category', 'date', 'body'));
$form->addSubmit('Добавить');
if($form->isSubmitted())
{
            $form->update();
            $form->js()->univ()->successMessage('Пост добавлен')->execute();
}
Was it helpful?

Solution

Model_Post

    $this->add('filestore/Field_Image', array(
        'name'=>'previewIMG',
        'use_model'=>'filestore/Model_Image'
    ));

filestore/Model_Image contains hook for thumb Expression getThumbURLExpr and filestore/Model_File (which is parent for filestore/Model_Image) contains hook for file (original image) getURLExpr

In this case your model will have two extra fields $m['url'] (original image) and $m['thumb_url'] (thumb).

This is simplest way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top