0

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();
}
Rakshazi
  • 75
  • 1
  • 10

1 Answers1

0

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.

Vadym
  • 749
  • 3
  • 15
  • ok it works, but how can I get path for uploaded image on posts feed page? – Rakshazi Nov 21 '13 at 11:56
  • i can't find these fields, my ways:
    $lister->getModel()->getField('previewIMG') $lister->getModel()->getField('previewIMG')->getModel()->getURLExpr() $lister->getModel()->getField('previewIMG')->getURLExpr()
    – Rakshazi Nov 23 '13 at 08:24
  • You don't need to call "getURLExpr" manually, there is a hook for these two methods. Just use $m['url'] and $m['thumb_url']. – Vadym Nov 25 '13 at 11:20