ruian / RuianUploadifyBundle

Add Uploadify support for symfony2
21 stars 8 forks source link

Warning: Missing argument 1 for Ruian\UploadifyBundle\Model\Resource::__construct() #13

Open dominikriedel opened 12 years ago

dominikriedel commented 12 years ago

Hey,

I just tried to implement the RuianUploadifyBundle into my project but ran into some problems after sending the form. Upload itself is running fine and the file is uploaded to the set directory. But when i hit the submit button and the form is send to the "new" action it runs into an exception.

"Warning: Missing argument 1 for Ruian\UploadifyBundle\Model\Resource::__construct(), called in /Applications/MAMP/htdocs/Lauschtour/vendor/symfony/src/Symfony/Component/Form/Extension/Core/Type/FieldType.php on line 142 and defined in /Applications/MAMP/htdocs/Lauschtour/vendor/bundles/Ruian/UploadifyBundle/Model/Resource.php line 19"

The Form is send with the following request: Form ->bind (array('baseData' => array('title' => 'test', 'shortDescription' => 'test', 'longDescription' => 'test', 'language' => '4'), '_token' => '6015ad221b39db0c355928d6236cd2b254e96831', 'file' => '/uploads/files/dda8271fcb3bd266a5f1cf18fa936505495c543d.png', 'picture_uploadify' => null))

Here is my "new" action: public function editCategoryAssetAction($categoryId, $assetTypeId, $assetId) {

    if ($assetId)
    {           
        $asset    = $this->getDoctrine()->getRepository('LauschtourMainBundle:Asset')->find($assetId);
    }
    else
    {
        $assetType  = $this->getDoctrine()->getRepository('LauschtourMainBundle:AssetType')->find($assetTypeId);
        $asset          = new Asset();
        $asset->setCategory($category);
        $asset->setAssetType($assetType);
    }

    if ($asset)
    {
        $form = $this->createForm(new EditAssetType($category->getMuseum()), $asset);

        if ($this->getRequest()->getMethod() == 'POST')
        {
            // bind form data tu user
            $form->bindRequest($this->getRequest());

            if ($form->isValid())
            {
                // update user
                $asset->save($this->getDoctrine());

                // send back to blank page

                return $this->redirect($this->generateUrl('manage_category_asset_edit', array('categoryId' => $categoryId, 'assetTypeId' => $assetTypeId)));
            }
        }
    }

    return $this->render('LauschtourFrontendBundle:Asset:editCategoryAsset.html.twig',array(
                                                                'category' => $category,
                                                                'assetTypeId' => $assetTypeId,
                                                                'asset' => $asset,
                                                    'form' => $form->createView(),
                                                                'referer' => $this->getRequest()->headers->get('referer'),
                                                                'success' => $this->getRequest()->get('success')));
}

Form Builder: public function buildForm(FormBuilder $builder, array $options) { $museum = $this->museum;

    $builder->add('fileUrl', 'hidden');     
    $builder->add('picture_uploadify', 'uploadify_resource', array(
                                                                                                 'data' => array(
                                                                                                 'folder'  => '/uploads/files/',
                                                                                                 'preview' => 'picture_preview',
                                                                                                 'path'    => 'manage_category_asset_upload',
                                                                                                 'copy'    => $this->getName() . '_' . 'fileUrl'),
                                                                                                    'property_path' => false));
    $builder->add('baseData', new EditExtendedBaseDataType($museum));
}

Does someone have an idea?

y1o1 commented 12 years ago

Guess DataTransformer make this help. c below http://symfony.com/doc/master/cookbook/form/data_transformers.html