zf2 tablegateway选择带连接表的列

时间:2016-08-15 03:01:17

标签: php mysql zend-framework

我有这个代码(工作正常):

Class SsoRequserTable

public function fetchAll()
    {
        $select = new Select();
        $select->from("sso_requser");       
        $select->join('sso_workunit', 'sso_workunit.sso_workunit_id = sso_requser.sso_workunit_id', array("unitname"), 'left');
        echo $select->getSqlString();
        $result = $this->tableGateway->selectWith($select);
        return $result;

    }

类SsoRequser

class SsoRequser{
    public $sso_requser_id;
    public $firstname;
    public $lastname;
    public $fullname;
    public $sso_workunit_id;

    public function exchangeArray($data){
        $this->sso_requser_id = (!empty($data['sso_requser_id'])) ? $data['sso_requser_id'] : null;
        $this->firstname = (!empty($data['firstname'])) ? $data['firstname'] : null;
        $this->lastname = (!empty($data['lastname'])) ? $data['lastname'] : null;
        $this->fullname = (!empty($data['fullname'])) ? $data['fullname'] : null;
        $this->sso_workunit_id = (!empty($data['sso_workunit_id'])) ? $data['sso_workunit_id'] : null;

    }
}

Module.php

public function getServiceConfig() {
        return array(
            'invokables' => array(
//                     'Aclplugin' => 'Auth\Controller\Plugin\Aclplugin',
            ),
            'factories' => array('SSO\Model\SsoRequserTable' => function($sm) {
                    $tableGateway = $sm->get('SsoRequserTableGateway');
                    $table = new SsoRequserTable($tableGateway);

                    return $table;
                },
                'SsoRequserTableGateway' => function ($sm) {
                    $dbAdapter = $sm->get('postgresql_adapter');
                    $resultSetPrototype = new HydratingResultSet();
                    $resultSetPrototype->setObjectPrototype(new SsoRequser());
                    return new TableGateway('sso_requser', $dbAdapter, null, $resultSetPrototype);
                },


            ),
        );
    }

但是我不能让sso_workunit列工作。我已经阅读了Zend文档,没有任何有效的工作方式。我需要名字才能有别名" unitname"。

我收到了消息错误" Undefined property: SSO\Model\Entity\SsoRequser::$unitname"

我是否应该在SsoRequser类中添加unitname? 有人可以帮帮我吗?

0 个答案:

没有答案