Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8363063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:05:22+00:00 2026-06-09T12:05:22+00:00

I am referencing the 2 step newsletter example at http://agiletoolkit.org/codepad/newsletter . I modified the

  • 0

I am referencing the 2 step newsletter example at http://agiletoolkit.org/codepad/newsletter. I modified the example into a 4 step process. The following page class is step 1, and it works to insert a new record and get the new record id. The problem is I don’t want to insert this record into the database until the final step. I am not sure how to retrieve this id without using the save() function. Any ideas would be helpful.

class page_Ssp_Step1 extends Page {
    function init(){
        parent::init();

        $p=$this;

        $m=$p->add(Model_Publishers);
        $form=$p->add('Form');
        $form->setModel($m);
        $form->addSubmit();
        if($form->isSubmitted()){

        $m->save();//inserts new record into db.
        $new_id=$m->get('id');//gets id of new record
        $this->api->memorize('new_id',$new_id);//carries id across pages
        $this->js()->atk4_load($this->api->url('./Step2'))->execute();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:05:23+00:00Added an answer on June 9, 2026 at 12:05 pm

    There are several ways you could do this, either using atk4 functionality, mysql transactions or as a part of the design of your application.


    1) Manage the id column yourself

    I assume you are using an auto increment column in MySQL so one option would be to not make this auto increment but use a sequence and select the next value and save this in your memorize statement and add it in the model as a defaultValue using ->defaultValue($this->api->recall(‘new_id’)


    2) Turn off autocommit and create a transaction around the inserts

    I’m from an oracle background rather than MySQL but MySQL also allows you to wrap several statements in a transaction which either saves everything or rollsback so this would also be an option if you can create a transaction, then you might still be able to save but only a complete transaction populating several tables would be committed if all steps complete.

    In atk 4.1, the DBlite/mysql.php class contains some functions for transaction support but the documentation on agiletoolkit.org is incomplete and it’s unclear how you change the dbConnect being used as currently you connect to a database in lib/Frontend.php using $this->dbConnect() but there is no option to pass a parameter.

    It looks like you may be able to do the needed transaction commands using this at the start of the first page

     $this->api->db->query('SET AUTOCOMMIT=0');
     $this->api->db->query('START TRANSACTION');
    

    then do inserts in various pages as needed. Note that everything done will be contained in a transaccion so if the user doesnt complete the process, nothing will be saved.
    On the last insert,

     $this->api->db->query('COMMIT');
    

    Then if you want to, turn back on autocommit so each SQL statement is committed

     $this->api->db->query('SET AUTOCOMMIT=1');
    

    I havent tried this but hopefully that helps.


    3) use beforeInsert or afterInsert

    You can also look at overriding the beforeInsert function on your model which has an array of the data but I think if your id is an auto increment column, it won’t have a value until the afterInsert function which has a parameter of the Id inserted.


    4) use a status to indicate complete record

    Finally you could use a status column on your record to indicate it is only at the first stage and this only gets updated to a complete status when the final stage is completed. Then you can have a housekeeping job that runs at intervals to remove records that didn’t complete all stages. Any grid or crud where you display these records would be limited with AddCondition(‘status’,’C’) in the model or added in the page so that incomplete ones never get shown.

    5) Manage the transaction as non sql

    As suggested by Romans, you could store the result of the form processing in session variables instead of directly into the database and then use a SQL to insert it once the last step is completed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Referencing question #2013421, I have the following RoR models: class Game < ActiveRecord::Base has_many
I'm trying to define a self referencing relationship for a workflow step where that
Referencing this Fiddle ( http://jsfiddle.net/j5uGN ), how can I toggle a clicked image's border
I'm referencing a static library . I've dragged the library project into my app
When referencing class properties from a function within the class do you use the
When writing and referencing elements in my Stylesheets, is ul#display-inline-block-example li And #display-inline-block-example ul
Is the .pdb file enough to debug and step into the code of a
I'm having trouble referencing one view controller from another. The code works but I
I am referencing the jQuery library, in a master page like so: <script type
I have a WorkerRole referencing a Class Library that calls some SOAP web services.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.