Skip to content

Instantly share code, notes, and snippets.

@asika32764

asika32764/README.md

Last active Apr 30, 2017
Embed
What would you like to do?
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