XF 2.2 Saving data directly to db (not submitting it)

FoxSecrets

Active member
I am trying to save data directly to db calling from the middle of another function (not by submitting process).
I can dump the data but it's not being saved. What's wrong? Is the filter related to new field or the incoming data?

Code:
public function createItem($data)
    {
        $item = $this->em()->create('My\Addon:Class');

        $input = $this->filter([
            'id'       => 'uint',
            'name'     => 'str',
            'qty'      => 'uint',
        ]);
        
        $input['name] = $data['name'];
        $input['qty'] = $data['qty'];

        $form = $this->formAction();
        $form->basicEntitySave($item, $input);

        return $form;
    }
 
I can dump the data but it's not being saved. What's wrong?
You've defined a method which sets up a form action object. To actually run it, you'd need to call $this->createItem($data)->run().

Is the filter related to new field or the incoming data?
\XF\Mvc\Controller::filter is a convenience shortcut for \XF\Http\Request::filter, which reads and sanitizes input from the request. It does not know anything about $data.
 
Top Bottom