Как сдвинуть поля результата mysql вверх, чтобы стать свойством класса

Как я могу подтолкнуть поля результата mysql вверх, чтобы стать свойством класса?

Например, это мой результат,

   object(ArticleModel)[4]
public 'item' =>
object(stdClass)[7]
public 'article_id' => string '4' (length=1)
public 'parent_id' => string '4' (length=1)
public 'template_id' => string '4' (length=1)
public 'type' => string 'page' (length=4)
public 'url' => string 'home' (length=4)
public 'title' => string 'Home' (length=4)
... and so on...

Я хочу, чтобы это было так,

object(stdClass)[7]
public 'article_id' => string '4' (length=1)
public 'parent_id' => string '4' (length=1)
public 'template_id' => string '4' (length=1)
public 'type' => string 'page' (length=4)
public 'url' => string 'home' (length=4)
public 'title' => string 'Home' (length=4)
... and so on...

Model, Mapper, Service ниже — классы, как я получаю результат выше (
object(ArticleModel)[4]public 'item' => [...]
).

модель,

class ArticleModel
{
// It is not ideal if I have to set the property manually.
public $article_id;
public $title;
public $url;
... and so on...
}

картографа,

class ArticleMapper
{
private $Database;

public function __construct(Database $pdo)
{
$this->Database = $pdo;
}

public function getRow($article_id)
{
$sql = "SELECT *
FROM article AS p
WHERE article_id = ?
";

$this->item = $this->Database->fetchRowObject($sql, $article_id);

return $this;
}

public function addContent()
{
...
}

public function mapRow(ArticleModel $ArticleModel, $article_id)
{
$ArticleModel->item = $this->getRow($article_id)->item;
}
}

оказание услуг,

class ArticleService
{
public function __construct(Database $pdo)
{
$this->Database = $pdo;
}

public function fetchRow($article_id)
{
$ArticleModel = new ArticleModel();
$ArticleMapper = new ArticleMapper($this->Database);
$ArticleMapper->mapRow($ArticleModel,$article_id);
return $ArticleModel;
}
}

просмотр / контроллер,

// Instance of Database.
$Database = new Database(DSN,DB_USER,DB_PASS);

// Make connection.
$Database->connect();

$ArticleService = new ArticleService($Database);
$article = $ArticleService->fetchRow(4);

var_dump($article);

результат,

object(ArticleModel)[4]
public 'item' =>
object(stdClass)[7]
public 'article_id' => string '4' (length=1)
public 'parent_id' => string '4' (length=1)
public 'template_id' => string '4' (length=1)
public 'type' => string 'page' (length=4)
public 'url' => string 'home' (length=4)
public 'title' => string 'Home' (length=4)
... and so on...

Я слежу за этим пример слайдшера сделать мой пример выше.

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …