Run composer require cakephp/orm:^4.0
Create Model/Entity/ArticleEntity.php
:
<?php
use Cake\ORM\Entity;
/**
* Class: Article
*/
class ArticleEntity extends Entity {
/**
* _accessible
*
* @var array
*/
protected $_accessible = [
'*' => true,
];
/**
* _getBody
*
* @param string $body
* @return string
*/
public function _getBody($body) {
return strtoupper($this->_fields['body']);
}
}
To use:
App::uses('ArticleEntity', 'Model/Entity');
// ...
$article = $this->Article->find('first');
$article = new ArticleEntity($article['Article']);
// ...
echo $article->body;