Add Model\Introduction class to DI registry

This commit is contained in:
nupplaPhil 2019-12-27 15:20:09 +01:00
parent 2cb449a0d5
commit df0c05d635
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
5 changed files with 10 additions and 15 deletions

View file

@ -32,10 +32,11 @@ abstract class BaseModel
*/
private $data = [];
public function __construct(Database $dba, LoggerInterface $logger)
public function __construct(Database $dba, LoggerInterface $logger, $data = [])
{
$this->dba = $dba;
$this->logger = $logger;
$this->data = $data;
}
/**
@ -71,15 +72,13 @@ abstract class BaseModel
*/
public function fetch(array $condition)
{
$intro = $this->dba->selectFirst(static::$table_name, [], $condition);
$data = $this->dba->selectFirst(static::$table_name, [], $condition);
if (!$intro) {
if (!$data) {
throw new HTTPException\NotFoundException(static::class . ' record not found.');
}
$this->data = $intro;
return $this;
return new static($this->dba, $this->logger, $data);
}
/**