Last active
April 30, 2017 14:11
-
-
Save asika32764/9aa16f0e207fccf8923454eb84aa6fff to your computer and use it in GitHub Desktop.
DataMapper with Entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @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