我需要在我的用户实体中拥有一个虚拟属性.我跟着
CakePHP book.
原文链接:https://www.f2er.com/php/130393.htmlUserEntity.PHP
namespace App\Model\Entity; use Cake\ORM\Entity; class User extends Entity { protected $_virtual = ['full_name']; protected function _getFullName() { return $this->_properties['firstname'] . ' ' . $this->_properties['lastname']; } }
在控制器中
$users = TableRegistry::get('Users'); $user = $users->get(29); $firstname = $user->firstname; // $firstname: "John" $lastname = $user->lastname; // $lastname: "Doe" $value = $user->full_name; // $value: null
我完全按照这本书,我只得到一个空值.