我是 Zend2 框架的新手,并且安装了 ZfcUser 并添加了一个我想通过以下方式访问的数据库列:
<?php echo $this->zfcUserIdentity()->getOrg(); ?>
任何有关扩展用户类以访问此变量的帮助将不胜感激。
瑞安
我是 Zend2 框架的新手,并且安装了 ZfcUser 并添加了一个我想通过以下方式访问的数据库列:
<?php echo $this->zfcUserIdentity()->getOrg(); ?>
任何有关扩展用户类以访问此变量的帮助将不胜感激。
瑞安
扩展 ZfcUser 用户实体以包含您的新属性和访问器。您需要在自己的模块中执行此操作,或者如果您使用的是骨架应用程序,则在Application
模块中可以正常工作。
<?php
namespace Application\Entity;
use ZfcUser\Entity\User;
class MyUser extends User
{
protected $org;
public function setOrg($org)
{
$this->org = $org;
return $this;
}
public function getOrg()
{
return $this->org;
}
}
复制vendor/ZfcUser/config/zfcuser.global.php.dist
到/config/autoload/zfcuser.global.php
在编辑器中打开刚刚复制的文件,然后找到下面的部分
/**
* User Model Entity Class
*
* Name of Entity class to use. Useful for using your own entity class
* instead of the default one provided. Default is ZfcUser\Entity\User.
* The entity class should implement ZfcUser\Entity\UserInterface
*/
//'user_entity_class' => 'ZfcUser\Entity\User',
取消注释该行,并将值替换为MyUser
您创建的实体的完全限定类名
'user_entity_class' => 'Application\Entity\MyUser',
然后尝试访问您的方法
<?php echo $this->zfcUserIdentity()->getOrg(); ?>