문제

I'm new to the Zend2 Framework and have installed ZfcUser with an added database column which I would like to access through:

<?php echo $this->zfcUserIdentity()->getOrg(); ?>

Any help on extending the User Class to access this variable would be greatly appreciated.

Ryan

도움이 되었습니까?

해결책

Extend the ZfcUser user entity to include your new property and accessors. You'll need to do this in your own module, or if you're using the skeleton app, in the Application module will work.

<?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;
    } 
}

Copy vendor/ZfcUser/config/zfcuser.global.php.dist to /config/autoload/zfcuser.global.php

Open the file you just copied in your editor, and find the section below

 /**
 * 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',

uncomment the line, and replace the value with the fully qualified class name of the MyUser entity you created

'user_entity_class' => 'Application\Entity\MyUser',

Then try accessing your method

<?php echo $this->zfcUserIdentity()->getOrg(); ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top