Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>using service in your entity is not a good pratice. I would recommand to create a form handler that performs validation, persistance and upload in this example</p> <p>i wrote an example that fits your needs</p> <pre><code>//... //inside a creation controller action //... //create a new page entity $page = new Page(); //get your page form class $form = $this-&gt;createForm(new PageForm(), $page); //call your form handler $formHandler = new PageFormHandler( $form, $this-&gt;get('request'), $this-&gt;get('your.gaufrette.filesystem'), $this-&gt;get('your.page.manager') ); //form is valid ? if ($formHandler-&gt;process()) { //flash message, redirection etc } </code></pre> <p>The handler class</p> <pre><code>namespace YourCompagnyBundle\Form\Handler; use YourCompagnyBundle\Entity\Page; use Symfony\Component\Form\Form; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\File\UploadedFile; use Gaufrette\Filesystem; class PageFormHandler { protected $form; protected $request; protected $pageManager; protected $filesystem; public function __construct(Form $form, Request $request, Filesystem $filesystem, $pageManager) { $this-&gt;form = $form; $this-&gt;request = $request; $this-&gt;filesystem = $filesystem; $this-&gt;pageManager = $pageManager; } public function process() { if( $this-&gt;request-&gt;getMethod() == 'POST' ) { $this-&gt;form-&gt;bind($this-&gt;request); if( $this-&gt;form-&gt;isValid() ) { $this-&gt;onSuccess($this-&gt;form-&gt;getData()); return true; } } return false; } function onSuccess(Page $page) { //has uploaded file ? if($page-&gt;getFile() instanceof UploadedFile){ //do some logic with gaufrette filesystem //if page is already managed in database (update), delete previous file } //storage $this-&gt;pageManager-&gt;save($page); } } </code></pre> <p>Hope this helped </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload