How to use POST attributes without saving it in the model?

I have an ActiveForm which is sending some data through POST, I have 2 fields which I don’t want to save in the database, I only need those attributes for data manipulating in the moment, so I just created them as attributes in the PHP model file. How can i access those attributes? I tried doing $model->attribute1, but it returns null, because this attribute isn’t in the database, but they are being sent int the POST request, in X-debug it shows something like:

$post: [
    Model: {
         id: 1
         name: "Example"
         attribute1: "The value I need, which is correct"
         attribute2: "Another value I need"

Where id and name are being saved in the database, while attribute1 and attribute2 aren’t.

They must be in model rules

1 Like


try to create var in your model’s class. For example:

class Student {
public $firstClass, $secondClass;