Skip to content

Instantly share code, notes, and snippets.

@asika32764
Last active April 30, 2017 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asika32764/9aa16f0e207fccf8923454eb84aa6fff to your computer and use it in GitHub Desktop.
Save asika32764/9aa16f0e207fccf8923454eb84aa6fff to your computer and use it in GitHub Desktop.
DataMapper with Entity
<?php
// administrator/components/com_flower/entity/sakura.php
/**
* The FlowerEntitySakura class.
*
* @property integer id
* @property string title
* @property string alias
* @property string introtext
* @property string fulltext
*/
class FlowerEntitySakura extends \Windwalker\DataMapper\Entity\Entity
{
public function __construct($fields = null, $data = null)
{
$fields = \Windwalker\Helper\DatabaseHelper::getColumns('#__flower_sakuras');
parent::__construct(array_keys($fields), $data);
}
}
<?php
// administrator/components/com_flower/mapper/sakura.php
use Windwalker\DataMapper\DataMapper;
class FlowerMapperSakura extends DataMapper
{
protected $table = '#__flower_sakuras';
protected function initialise()
{
parent::initialise();
$this->setDataClass('FlowerEntitySakura');
}
}
/** @var FlowerEntitySakura $sakura */
$sakura = (new FlowerMapperSakura)->findOne(3);
$sakura->id;
$sakura->title;
$sakura->alias;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment