Forum

Thread tagged as: Question, Api, Add-on-development

How do I insert a row into a db table with a custom app?

I am trying to build a custom app, that allows members of the site to edit and add to a list of items that live in a database table belonging to that app.
I am able to update a row in that table with

$Contracts = new Frwssr_Contracts($API);
if (is_object($Contracts)) $Contract = $Contracts->find($SubmittedForm->data['id']);
if (is_object($Contract)) {
  $Contract->update_contract($SubmittedForm);
}

The corresponding function in Frwssr_Contract looks like this:

    public function update_contract($SubmittedForm)
    {
        $data = $SubmittedForm->data;

        $out = array();

        foreach($data as $key=>$val) {

            if (array_key_exists($key, $this->field_aliases)) {
                $out[$this->field_aliases[$key]] = $val;
                $key = $this->field_aliases[$key];
            }
        }

        $this->update($out);

    }

Deleting a row does work in a similar fashion.
But what do I need to do to insert a new item/row into the db table?
I tried a lot of things, but obviously I am not completely grasping the concept of object-oriented PHP.
Any suggestions are appreciated.

Nils Mielke

Nils Mielke 3 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Use the create() method on your Frwssr_Contracts class.

Got it.
Thank you so much, Drew.