B
B
beta-it2017-09-20 14:28:15
Yii
beta-it, 2017-09-20 14:28:15

How to work with Model::loadMultiple without a form?

Good afternoon.
Can you please tell me how to use loadMultiple without a form?
There is a console controller that serves to process files, and, accordingly, write to the database:

public function actionLoad()
    {
        //...
        foreach ($this->files as $file) {
        
                $clients[] = new ClientModel();

                $list = self::parseXMLFile($file);

                if (Model::loadMultiple($clients, $list, '')){
                    print_r($clients);
                } else {
                    print_r($clients);
                }
              // ...
                
            }
           // ...
    }

If I do it through load(), then everything goes:
$client = new ClientModel();
$client->load($list[1], '');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-09-20
@beta-it

Check that you $list
must have an array with the key ClientModel, like:

[
  'ClientModel'=>['someAttribute'=>'somedata'],
  'SecondModel'=>['someAttribute'=>'somedata']
]

if not, then it looks like this:
$list = ['ClientModel'=>self::parseXMLFile($file)];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question