Get ['DT_RowId'] before calling process( $_POST )

Get ['DT_RowId'] before calling process( $_POST )

INTONEINTONE Posts: 153Questions: 58Answers: 6

I want to know if there is a way to get the ['DT_RowId'] which is basically mysql_insert_id equivalent before calling the process( $_POST ). example code below of what i want to do:

$data = Editor::inst( $db, 'site','site_id' )
->fields(
//all fields
);

  //this should create additional records without writing sql without the site_id
  if ( isset($_POST['action']) && ($_POST['action'] === "create" || $_POST['action'] === "edit") ) {

  $_POST['data']['ad_agency_site']['site_id'] = $site_id;
  $_POST['data']['ad_agency_site']['ad_agency_branch_id'] = $_POST['data']['ad_agency_branches']['ad_agency_branch_id'];


}

however site_id seem to only be created after calling something like:

$out = $data->process( $_POST )->data();

if I were to do this:

$out = $data->process( $_POST )->data();
if ( isset($_POST['action']) && ($_POST['action'] === "create" || $_POST['action'] === "edit") ) {

  $_POST['data']['ad_agency_site']['site_id'] = $out['row']['DT_RowId'];
  $_POST['data']['ad_agency_site']['ad_agency_branch_id'] = $_POST['data']['ad_agency_branches']['ad_agency_branch_id'];


}

the additional records would not be created/edited authomatically and I would have to write sql statements to achieve the same result because process call would have removed the POST VARS. Hense my question of if I can get the site id and still be allowed to call POST['data']?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,863Questions: 1Answers: 10,135 Site admin
    Answer ✓

    On edit you can get the id that is being used with $_POST['id'] (see the client / server communication docs). However, on create, obviously the id won't exist until the row has actually been created (which is done by process()).

    Allan

This discussion has been closed.