所以我想在我的数据库中将数据数据保存为test。
我的保存代码在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());
}
}
}
现在我尝试在$resultlog = new ResultLog();
的ExportAllProductsShell.php中调用它,但似乎它不起作用。
我是这样做的。
<?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()不能执行。
有什么问题或缺乏?