Wednesday, 15 February 2012

symfony - Doctrine Behaviors fields in Symfony2 auto-generated CRUD -


I am starting with symphony and I have a unit of "post"

  & Lt;? Php namespace My \ BackendBundle \ Entity; Use the theory / ORM \ mapping as an ORM; Use \ Mapping \ Annotation as Gedmo; / ** * Post * * @ORM \ Table () * @ORM \ Entity * / class Post {/ ** * @ Integer * * @ORM \ column (name = "id", type = "integer") * @ ORM \ Id * @ORM \ Generated Values ​​(strategy = "auto") * / personal $ id; / ** * @ string string * * @ORM \ column (name = "title", type = "string", length = 255) * / personal $ title; / ** * Water String * * @Godmo \ Slug (field = {"title"}) * @ORM \ column (type = "string", length = 255, unique = true) * / private $ slug; / ** * @ string string * * @ORM \ column (name = "text", type = "text") * / private $ text; / ** * Get ID * * Return return * / Public function getId () {Return $ -> ID-; } / ** * Set Title * * @ The Ultimate String $ Title * @Ruran Post * / Public Function Settle ($ title) {$ this- & gt; Title = $ title; $ This return; } / ** * Get the title * * @ Returning string * / public function getTitle () {Return $ this- & gt; Title; } / ** * Set text * * @ Exact string $ text * @ roar post * / Public function set text ($ text) {$ this- & gt; Text = $ text; $ This return; } / ** * Get Text * * @ Layer String * / Public Function getText () {Return $ this- & gt; Text; } / ** * Set the slug * * @ The ultimate string $ slug * @ return post * / public function set slug ($ slug) {$ this- & gt; Slug = $ slug; $ This return; } / ** * Get Slug * * @ Layer String * / Public Function getSlug () {Return $ this- & gt; Slog; }}   

I have created a table in the database:

  app / console theory: schema: update - force   < P> and CRUD Panel:  
  App / console theory: Generated: crud   

with option:

  : MyBackendBundle: Post "Write" Action: Yes   

But as you can see, I have a "Slug" field and I want the principle to self-generate it But the default CRUD panel on "/ post / new" has input for all 3 areas (title, slug, and text). And only after a few hours of searching for the solution can I manually delete "slug" input from my / BackendBundle / Form / PostType.php.

I do not know whether I am doing something wrong or does it just do such a thing? Slugable behaviors work well when I'm manually adding the unit (by creating a new text with the title) and text and $ manager- & gt; Flush ()) I am doing.

My / APP / config / config.yml file:

  Import: - {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: ~ verification: {enable_annotations: true} templating : Engine: ['twig'] #assets_version: SomeVersionScheme default_locale: "% locale%" trusted_proxies: ~ session: ~ pieces: ~ # twist configuration twist: debug:% kernel.debug% strict_variables:% kernel.debug% # assetic configuration Asset: debug:% kernel.debug% use_controller: false bundles: [] #java: / usr / bin / java filter: cssrewrite: ~ #closure: #jar:% kern El.root_dir% / resource / java / compiler.jar #yui_css: # jar:% kernel.root_dir% / resource / java / yuicompressor -2.4.7. # Principle Configuration Principles ne: 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 path to Parameters.yml # example Database_path: % Kernel.root_dir% / data / data.db3 # path:% database_path% orm: auto_generate_proxy_classes: kernel.debug% auto_mapping: true mapping: stoff doccrin extension bundle: incorrect stof_ Dictation_Extension: Default_Locale: N_US ORM: Default: Lazy: True # Swift Mailer 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 \ unit \ user   

If this is normal and I have to do it manually then simple confirmation will be very good.

app / console theory: generate: crud Generates fields for all unit properties.

Yes, you should remove unnecessary fields from the form or should use more adverced such as generator

No comments:

Post a Comment