Итак, я хочу сохранить массив данных в качестве теста в моей базе данных.
Мой код для сохранения находится в ResultLog.php
<?php
namespace Alis\Mall\Alpen\Domain\Log;
use Alis\MultiDbConnection\ClientDbConnectionManager;
use Cake\ORM\TableRegistry;
class ResultLog
{
private $MallExportResultLog;
public function __construct()
{
$MallExportResultLog = TableRegistry::get('MallExportResultLog');
}
/**
*/
public function save()
{
$MallExportResultLog->setConnection(ClientDbConnectionManager::getInstance()->getConnection());
$data = [
'stream_name' => "test",
'stream_version' => 1,
'event_type' => "test",
'data' => "test"
];
$entity = $MallExportResultLog->newEntity($data);
if (! $MallExportResultLog->save($entity)) {
throw new \Exception($entity->errors());
}
}
}
Теперь я пытаюсь вызвать его в ExportAllProductsShell.php, в $resultlog = new ResultLog();
, но похоже, что он не работает.
Вот как я это делаю.
<?php
namespace App\Shell;
use Cake\Console\Shell;
use Alis\Mall\Alpen\UseCase\ExportAllProducts;
use Alis\Mall\Alpen\Domain\Log\ResultLog;
/**
* ExportAllProductsShell shell command.
*/
class ExportAllProductsShell extends Shell
{
public function main()
{
$this->out('Start Execute.');
$export = new ExportAllProducts();
$export->export();
$resultlog = new ResultLog();
$this->out('Finish Execute.');
}
}
ExportAllProducts () выполняется, но ResultLog () не может.
Что не так или не хватает?