Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine Behaviors fields in Symfony2 auto-generated CRUD
    text
    copied!<p>I'm starting with Symfony and I have Entity "Post"</p> <pre><code>&lt;?php namespace My\BackendBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; /** * Post * * @ORM\Table() * @ORM\Entity */ class Post { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="title", type="string", length=255) */ private $title; /** * @var string * * @Gedmo\Slug(fields={"title"}) * @ORM\Column(type="string", length=255, unique=true) */ private $slug; /** * @var string * * @ORM\Column(name="text", type="text") */ private $text; /** * Get id * * @return integer */ public function getId() { return $this-&gt;id; } /** * Set title * * @param string $title * @return Post */ public function setTitle($title) { $this-&gt;title = $title; return $this; } /** * Get title * * @return string */ public function getTitle() { return $this-&gt;title; } /** * Set text * * @param string $text * @return Post */ public function setText($text) { $this-&gt;text = $text; return $this; } /** * Get text * * @return string */ public function getText() { return $this-&gt;text; } /** * Set slug * * @param string $slug * @return Post */ public function setSlug($slug) { $this-&gt;slug = $slug; return $this; } /** * Get slug * * @return string */ public function getSlug() { return $this-&gt;slug; } } </code></pre> <p>I've generated table in database:</p> <pre><code>app/console doctrine:schema:update --force </code></pre> <p>And CRUD panel:</p> <pre><code>app/console doctrine:generate:crud </code></pre> <p>with options:</p> <pre><code>Entity: MyBackendBundle:Post "write" action: yes </code></pre> <p>But as you can see, I have "slug" field and I want Doctrine to auto-generate it. But default CRUD panel at "/post/new" have inputs for all 3 fields (title, slug and text). And after hours of searching for solution only one I can do is manually delete "slug" input from My/BackendBundle/Form/PostType.php.</p> <p>I don't know if I'm doing something wrong or it's just works like that? Sluggable behavior works good when I'm adding entity manually (by creating new Post() with title and text and doing $manager->flush()).</p> <p>My /app/config/config.yml file:</p> <pre><code>imports: - { resource: parameters.yml } - { resource: security.yml } framework: #esi: ~ translator: { fallback: %locale% } secret: %secret% router: resource: "%kernel.root_dir%/config/routing.yml" strict_requirements: ~ form: ~ csrf_protection: ~ validation: { enable_annotations: true } templating: engines: ['twig'] #assets_version: SomeVersionScheme default_locale: "%locale%" trusted_proxies: ~ session: ~ fragments: ~ # Twig Configuration twig: debug: %kernel.debug% strict_variables: %kernel.debug% # Assetic Configuration assetic: debug: %kernel.debug% use_controller: false bundles: [ ] #java: /usr/bin/java filters: cssrewrite: ~ #closure: # jar: %kernel.root_dir%/Resources/java/compiler.jar #yui_css: # jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar # Doctrine Configuration doctrine: dbal: driver: %database_driver% host: %database_host% port: %database_port% dbname: %database_name% user: %database_user% password: %database_password% charset: UTF8 # if using pdo_sqlite as your database driver, add the path in parameters.yml # e.g. database_path: %kernel.root_dir%/data/data.db3 # path: %database_path% orm: auto_generate_proxy_classes: %kernel.debug% auto_mapping: true mappings: StofDoctrineExtensionsBundle: false stof_doctrine_extensions: default_locale: en_US orm: default: sluggable: true # Swiftmailer Configuration swiftmailer: transport: %mailer_transport% host: %mailer_host% username: %mailer_user% password: %mailer_password% spool: { type: memory } fos_user: db_driver: orm firewall_name: main user_class: My\UserBundle\Entity\User </code></pre> <p>If it's normal and I have to do it manually simple confirmation would be great.</p>
 

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