如何遍历实体属性Doctrine

时间:2015-08-12 13:30:54

标签: php codeigniter doctrine entities

Dectrine创建的实体。即用户 为了能够在db中输入用户,我有这个模型的setUser():

function setUser(){
    /**
     * @var Users $user
     */

    $user=new Users();

    $user->setFirstName($this->input->post('first_name'));
    $user->setLastName($this->input->post('last_name'));
    $user->setEmailAddress($this->input->post('email_address'));
    $user->setUsername($this->input->post('username'));
    $user->setPassword($this->input->post('password'));

    try{
        //save to database
        $this->em->persist($user);
        $this->em->flush();

    } catch (Exception $ex) {
        die($ex->getMessage());

    }
    return true;
}

我没有声明每个setter,而是想要遍历所有属性。 我怎样才能做到这一点? 类似的东西:

$array=$user->eachProperty;

只是为了得到一个数组: 阵列(FirsName,姓氏,EmailAddress的) 就是这样。我基本上只是在寻找Doctrine函数。

这样我就可以迭代并自动创建setter。 感谢。

0 个答案:

没有答案