PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 16, 2022

[FIXED] How to set a default value in AssociationField EasyAdmin 3

 February 16, 2022     easyadmin3, php, symfony     No comments   

Issue

I'm starting with EasyAdmin v3. I want to set a default value in easyAdmin. In php/symfony i would provide:

$article = new Article::class;
$article->setAuthor($user)

Before creating the form to set the currentUser in my entity but with EA3 i don't know how to manage this.

Thanks


Solution

You can override methods like createEntity():

class ArticleCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Article::class;
    }

    public function createEntity(string $entityFqcn)
    {
        $article = new Article();
        $article->setAuthor($this->getUser())

        return $article;
    }

    // ...
}

See this part of the documentation for more information.



Answered By - Stephan Vierkant
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing