Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9131289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:07:08+00:00 2026-06-17T08:07:08+00:00

Okay, this gets a little convoluted, so bear with me. I’ll try and keep

  • 0

Okay, this gets a little convoluted, so bear with me. I’ll try and keep it clear and concise.

I’m using Symfony2’s very nice form builder system for simple crud, but the basic file upload element doesn’t quite meet my needs, so I want to extend it by adding a thumbnail preview, and some other niceties.

Reading this, I found that I can create my own custom template block for rendering file elements:

http://symfony.com/doc/master/cookbook/form/form_customization.html#twig

Which is really cool, and seems to be working perfectly. However, I’m storing the path for my file upload in a separate attribute in the entity, based on this:

http://symfony.com/doc/master/cookbook/doctrine/file_uploads.html

So, I need some way for the template to access the path field. I created a custom FileType class like this:

<?php

namespace TechPeople\InvoiceBundle\Component\Form\Type;

use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;

use Symfony\Component\Form\Extension\Core\Type\FileType as SymfonyFileType;

class FileType extends SymfonyFileType {
    /**
     * {@inheritdoc}
     */
    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $view->vars = array_replace($view->vars, array(
            'type'  => 'file',
            'value' => '',
            'path' => $options['path'],
        ));
    }
}

And then I passed the file path into the form builder like this:

<?php

namespace TechPeople\InvoiceBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class InvoiceType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        echo 'test';
        $builder
            ->add('month')
            ->add('year')
            ->add('expenses')
            ->add('due')
            ->add('paid')
            ->add('created')
            ->add('expense_amount', 'money')
            ->add('total_amount', 'money')
            ->add('attachment', 'file', array('path'=>$options['data']->getAttachmentPath()))
            ->add('vendor')
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'TechPeople\InvoiceBundle\Entity\Invoice'
        ));
    }

    public function getName()
    {
        return 'techpeople_invoicebundle_invoicetype';
    }
}

Well, that seemed pretty groovy, but then I get this error loading the form:

The option "path" does not exist. Known options are: "attr", "block_name", "by_reference", "cascade_validation", "compound", "constraints", "csrf_field_name", "csrf_protection", "csrf_provider", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "intention", "invalid_message", "invalid_message_parameters", "label", "label_attr", "mapped", "max_length", "pattern", "post_max_size_message", "property_path", "read_only", "required", "translation_domain", "trim", "validation_constraint", "validation_groups", "virtual"
500 Internal Server Error - InvalidOptionsException

So, it looks like there’s a list of allowed options somewhere, but I can’t find it. Additionally, I’m not 100% sure that the add() method in InvoiceType is passing the options array to the buildView() method in FileType. I’m having trouble tracing the code between these two things.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:07:09+00:00Added an answer on June 17, 2026 at 8:07 am

    First of all, once you created your custom class, you should declare it (register it) to be used as file type:
    http://symfony.com/doc/current/reference/dic_tags.html#form-type

    <?php
    
    namespace TechPeople\InvoiceBundle\Component\Form\Type;
    
    use Symfony\Component\Form\FormInterface;
    use Symfony\Component\Form\FormView;
    
    use Symfony\Component\Form\Extension\Core\Type\FileType as SymfonyFileType;
    
    class FileType extends SymfonyFileType 
    {
    /**
     * {@inheritdoc}
     */
    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $view->vars = array_replace($view->vars, array(
            'type'  => 'file',
            'value' => '',
            'path' => $options['path'],
        ));
    }
    
    /**
     * {@inheritdoc}
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'path' => null,
        ));
    }
    
    /**
     * {@inheritdoc}
     * 
     * POTENTIALLY declare it as child of file type.
     */
    public function getParent()
    {
        return 'file';
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so this is complicated so try to bear with me, i will try
Okay this question is very simple: I have a facebook page, and a website.
Okay this is werid, i keep getting the error, randomly. ValueError: matrix must be
Okay this is very hard to explain, but i want to add padding to
Okay, this all takes place in a nice and simple 2D world... :) Suppose
Okay this is definitely a n00b question but here goes. The way I understand
Okay this is definitley an easy question and a stupid one but since I
Okay this may be a simple question but I have yet to come with
Okay this is my 4th question today on Scheme, still pretty new to Scheme,
Okay this is probably a really dumb question, however it's really starting to hurt.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.