CakePHP How to get latest auto incremented id after saving data -


I have also examined the question as well. I am trying to apply the model described in question.

What I want to do, on the Anch function of the message controller, make a record in the thread table (this table has only 1 field, which is the primary key and auto increment), then take your ID and Insert this message in the table with the User ID that I already have, and then save it in the message_read_state and thread_participant table.

This is what I am trying to do in the thread model:

  function saveThreadAndGetId () {// $ data = array ('thread' = & gt; array )); $ Data = array ('id' = & gt; ''); // debugger :: dump (print_r ($ data)); $ This- & gt; Save ($ data); Debug ('id:'. $ This-> ID); $ Thread id = $ this- & gt; GetInsertID (); Debug ($ threadid); $ Thread id = $ this- & gt; GetLastInsertId (); Debug ($ threadid); Die (); Return $ thread; } $ Data = array ('id' = & gt; '');   

This row from the above function adds a line to the thread table, but I am unable to retrieve the ID. Can I get the ID by any means or am I saving it incorrectly?

Initially, I was doing a query object in the message controller:

  $ ->; Thread- & gt; Query ('thread value INSERT ();');   

But then I found out that the last function does not work on manual queries, so I returned.

You can change the $ data to '' IDs are originally set to an empty array. Not sure what you were expecting from him :) Try not to manually set 'id' in empty string, and save some data. So you should get the ID properly

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -