php - how to set auto increment id in doctrine2 odm in zf2? -


I have used the doctrine2 odm in zf2 and I want to create automatic increment ID, I auto increment the calendar id But do not save it in the database, how can I increase the Calendar ID auto and save it in the database? Here's my code:

  & lt; Php namespace calendar \ documents; Use the principle \ ODM \ MongoDB \ mapping \ annotation as ODM; // Use theory \ ODM \ MongoDB \ DocumentRepository; / ** @ODM document (collection = "calendar") * / class calendar {/ ** @ODM \ Id * / private $ id; / ** @ODM \ field (type = "int", strategy = "sequence") * / personal $ calendar_id; / ** @ ODM \ field (type = "intestine") * / personal $ user_id; / ** @ ODM \ field (type = "string") * / private $ title; / ** @ ODM \ field (type = "string") * / personal $ details; / ** * Return table field * / Public function getProperty ($ property) {if (property_exists ($ $, $ properties)) {$ $ - $ property; }} Public Function Setting Property ($ property, $ value) {if (property_exists ($ this, $ property)) {$ this- & gt; $ property = $ value; } $ Returned; } Public function getData () {Returns array ('id' =>> $ this-> ID, 'calendar_id' = & gt; calendar_id, 'user_id' => $ this- & gt; user_id, title '=> $ this- & gt; title,' description '=> $ - this-> description); }}   

And this is my form:

  & lt ;? Php namespace calendar 'form; Use Zend \ Form \ Form; Class Calendar Form Form Form (Public Function __ Construct ($ name = null) {// We want to ignore the name passed by name: __ Construction ('Calendar'); $ This-> Set Attribute (' Method ',' post '); $ this- & gt; addition (array (' name '= & gt;' calendar_id ',' attributes' = & gt; array ('type' = & gt; 'hidden',) ))); $ This- & gt; Addition (array ('name' = & gt; 'user_id', 'attributes' = & gt; array ('type' = & gt; 'hidden',)))); Array ('label', 'name' => array ('type' => gtc: 'text',), 'option' => array ('label' = & gt; title ',) )); $ (- '' '' '' '' '' '' 'and' = & Gt; 'description',),)); Add ('type' = & gt; 'submit', 'value' = & gt; 'save', 'id' (array ('name' = & gt; submit ',' attributes' = & gt; = & Gt; 'submitbutton',),))); }}   

And here's my text code:

  public function createAction () {$ dm = $ this- & gt; GetServiceLocator () - & gt; Ho ('doctrine.documentmanager.odm_default'); $ Form = new calendar form (); $ Update = false; $ Message = ''; If ($ this-> getRequest () -> isPost ()) {$ post = $ this- & gt; getRequest () - & gt; GetPost (); $ Form & gt; setInputFilter ($ form> getInputFilter ()); $ Form & gt; SetData ($ post); If ($ form-> isValid ()) {$ formData = $ form-> GetData (); $ S = new calendar (); $ S- & gt; setProperty ('CALENDAR_ID', $ _ post ['calendar_id']); $ S- & gt; SetProperty ('user_id', 1); $ S- & gt; SetProperty ('title', $ post ['title']); $ S- & gt; SetProperty ('description', $ post ['description']); $ Dm-> Continues ($ s); $ Dm-> Flush (); $ Update = 1; $ Message = 'Calendar successfully added.'; // $ form = new calendar form (); // $ this- & gt; Redirect () - & gt; toRoute ('Calendar'); }} Returns array ('form' = & gt; $ form, 'add_message' = & gt; $ message, 'updates' => $ update, 'calendar' = & gt; $ this- & gt; calendar) ; } 

Here there is some principle 2 animation code, which is the column "id" as primary Sets the key and auto-sync for this table. @ORM \ Id * @ORM = Generated Values ​​(strategy = " Auto ") * / Protected $ id;

Your mistake is that you have created

  strategy = "INCREMENT"   

instead strategy = "auto"

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -