Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 条令一对一空结果_Php_Symfony_Doctrine Orm - Fatal编程技术网

Php 条令一对一空结果

Php 条令一对一空结果,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,用户实体: <?php namespace App\Entity; use App\Entity; use Doctrine\ORM\Mapping; /** * @Entity * @Table(name="users", options={"collate":"utf8_general_ci", "charset":"utf8", "engine":"MyISAM"}) */ class Users extends Entity { /** * One

用户实体:

<?php

namespace App\Entity;

use App\Entity;
use Doctrine\ORM\Mapping;

/**
 * @Entity
 * @Table(name="users", options={"collate":"utf8_general_ci", "charset":"utf8", "engine":"MyISAM"})
 */
class Users extends Entity {

    /**
     * One Users has One UserInformation. Inversed here.
     * @OneToOne(targetEntity="UserInformation",mappedBy="users")
     */
    protected $userInformation;

    /**
     * @Column(type="string", length=50)
     * @var string
     */
    protected $email;

    /**
     * @Column(type="string", length=50)
     * @var string
     */
    protected $encrypted_password;

    /**
     * @Column(type="string", length=10)
     * @var string
     */
    protected $salt;

    /**
     * @Column(type="smallint", options={"default":"0","comment":"0 : Doctor, 1 : Assistant, 2 : Student"}))
     * @var smallint
     */
    protected $type;

    /**
     * @Column(type="string", length=150)
     * @var string
     */
    protected $sef_link;

    /**
     * @return mixed
     */
    public function getUserInformation() {
        return $this->userInformation;
    }

    /**
     * @param mixed $userInformation
     */
    public function setUserInformation($userInformation) {
        $this->userInformation = $userInformation;
    }

    /**
     * @return string
     */
    public function getEmail() {
        return $this->email;
    }

    /**
     * @param string $email
     */
    public function setEmail($email) {
        $this->email = $email;
    }

    /**
     * @return string
     */
    public function getEncryptedPassword() {
        return $this->encrypted_password;
    }

    /**
     * @param string $encrypted_password
     */
    public function setEncryptedPassword($encrypted_password) {
        $this->encrypted_password = $encrypted_password;
    }

    /**
     * @return string
     */
    public function getSalt() {
        return $this->salt;
    }

    /**
     * @param string $salt
     */
    public function setSalt($salt) {
        $this->salt = $salt;
    }

    /**
     * @return integer
     */
    public function getType() {
        return $this->type;
    }

    /**
     * @param integer $type
     */
    public function setType($type) {
        $this->type = $type;
    }

    /**
     * @return string
     */
    public function getSefLink() {
        return $this->sef_link;
    }

    /**
     * @param string $sef_link
     */
    public function setSefLink($sef_link) {
        $this->sef_link = $sef_link;
    }
}
getUserInformation返回空的。。。 如果调用
getResultArray()
而不是
getSingleResult()
,则信息会随数据一起返回。但是这次,我不能像这样使用,
$user->getId()
。我只返回
$user
。 因此,我想调用
$user
作为对象数组。信息返回为空

{“error”:false,“user”:{ “id”:27, “电子邮件”:test@email.com", “类型”:1, “资料”:{}, “创建于”:{ “日期”:“2017-01-01 21:05:45.000000”, “时区类型”:3, “时区”:“欧洲/柏林” }, “更新地址”:{ “日期”:“2017-01-01 21:05:45.000000”, “时区类型”:3, “时区”:“欧洲/柏林” }, “是否已删除”:false}

下面是if
getQuery()->getArrayResult()
返回$user

{“error”:false,“user”:[ { “电子邮件”:test@email.com", “加密密码”:“vjvyW2E9/MT7pll01S6uBeFIvO9lNzI1N2VjYjEx”, “盐”:“e7257ecb11”, “类型”:1, “sef_链接”:“测试”, “id”:27, “创建于”:{ “日期”:“2017-01-01 21:05:45.000000”, “时区类型”:3, “时区”:“欧洲/柏林” }, “更新地址”:{ “日期”:“2017-01-01 21:05:45.000000”, “时区类型”:3, “时区”:“欧洲/柏林” }, “是否已删除”:false, “用户信息”:{ “标题”:“测试1”, “名称”:“测试”, “姓氏”:“测试”, “出生”:空, “性别”:0, “地址”:空, “国家/地区id”:空, “关于”:空, “机构”:空, “专业领域”:空, “cv_路径”:空, “facebook_链接”:空, “推特链接”:空, “instagram_链接”:空, “linkedin_链接”:空, “img_path”:“default profile female.png”, “大学”:空, “大学毕业于”:空, “md”:空, “md_毕业于”:空, “副教授”:空, “副教授毕业于”:空, “id”:16, “创建于”:{ “日期”:“2017-01-01 21:05:45.000000”, “时区类型”:3, “时区”:“欧洲/柏林” }, “更新地址”:{ “日期”:“2017-01-01 21:05:45.000000”, “时区类型”:3, “时区”:“欧洲/柏林” }, “是否已删除”:false } }]}


我自己也遇到过这个问题,当使用dumps检查要获取的数据时,它显示为null,您是否尝试过(例如)
getUserInformation->getTitle()


只需创建一个for循环,因此
foreach(用户作为getUserInformation)
。这应该可以做到

我自己也遇到过这个问题,当使用dumps检查要获取的数据时,它显示为null,您是否尝试过(例如)
getUserInformation->getTitle()


只需创建一个for循环,因此
foreach(用户作为getUserInformation)
。这应该可以做到

我自己也遇到过这个问题,当使用dumps检查要获取的数据时,它显示为null,您是否尝试过(例如)getUserInformation->getTitle()。返回的是什么?返回的是数据,但如果userinformation有多个数据,如何获取@Kevinthegreat你是说你有一个数组?只要做一个for循环,就可以使用foreach(用户作为getUserInformation)。这样就可以了it@KevinTheGreat你是对的,谢谢:)我会给你一个答案,这样你就可以关闭这个QI。我自己也有这个问题,当使用dumps检查要获取的数据时,它说null,你是否尝试过(例如)getUserInformation->getTitle()。返回的是什么?返回的是数据,但如果userinformation有多个数据,如何获取@Kevinthegreat你是说你有一个数组?只要做一个for循环,就可以使用foreach(用户作为getUserInformation)。这样就可以了it@KevinTheGreat你是对的,谢谢:)我会回答你,这样你就可以结束这个问题了
<?php

namespace App\Entity;

use App\Entity;
use Doctrine\ORM\Mapping;

/**
 * @Entity
 * @Table(name="user_information", options={"collate":"utf8_general_ci", "charset":"utf8", "engine":"MyISAM"})
 */
class UserInformation extends Entity {

    /**
     * One UserInformation has One Uses. Mapped here.
     * @OneToOne(targetEntity="Users")
     * @JoinColumn(name="uid", referencedColumnName="id")
     */
    protected $users;

    /**
     * @Column(type="string", length=50)
     * @var string
     */
    protected $title;

    /**
     * @Column(type="string", length=50)
     * @var string
     */
    protected $name;

    /**
     * @Column(type="string", length=50)
     * @var string
     */
    protected $surname;

    /**
     * @Column(type="date", nullable=true)
     * @var date
     */
    protected $born;

    /**
     * @Column(type="smallint", options={"default" : "0", "comment":"0 : Female, 1 : Male"}))
     * @var smallint
     */
    protected $gender;

    /**
     * @Column(type="text", length=65532, nullable=true)
     * @var text
     */
    protected $address;

    /**
     * @Column(type="integer", nullable=true)
     * @var integer
     */
    protected $country_id;

    /**
     * @Column(type="text", length=65532, nullable=true)
     * @var text
     */
    protected $about;

    /**
     * @Column(type="string", length=50, nullable=true)
     * @var string
     */
    protected $institution;

    /**
     * @Column(type="text", length=65532, nullable=true)
     * @var text
     */
    protected $area_of_expertise;

    /**
     * @Column(type="string", length=100, nullable=true)
     * @var string
     */
    protected $cv_path;

    /**
     * @Column(type="string", length=50, nullable=true)
     * @var string
     */
    protected $facebook_link;

    /**
     * @Column(type="string", length=50, nullable=true)
     * @var string
     */
    protected $twitter_link;

    /**
     * @Column(type="string", length=50, nullable=true)
     * @var string
     */
    protected $instagram_link;

    /**
     * @Column(type="string", length=50, nullable=true)
     * @var string
     */
    protected $linkedin_link;

    /**
     * @Column(type="string", length=100)
     * @var string
     */
    protected $img_path;

    /**
     * @Column(type="string", length=50, nullable=true)
     * @var string
     */
    protected $university;

    /**
     * @Column(type="date", nullable=true)
     * @var date
     */
    protected $university_graduated_at;

    /**
     * @Column(type="string", length=50, nullable=true)
     * @var string
     */
    protected $md;

    /**
     * @Column(type="date", nullable=true)
     * @var date
     */
    protected $md_graduated_at;

    /**
     * @Column(type="string", length=50, nullable=true)
     * @var string
     */
    protected $associate_professor;

    /**
     * @Column(type="date", nullable=true)
     * @var date
     */
    protected $associate_professor_graduated_at;

    /**
     * @return mixed
     */
    public function getUsers() {
        return $this->users;
    }

    /**
     * @param mixed $users
     */
    public function setUsers($users) {
        $this->users = $users;
    }

    /**
     * @return string
     */
    public function getTitle() {
        return $this->title;
    }

    /**
     * @param string $title
     */
    public function setTitle($title) {
        $this->title = $title;
    }

    /**
     * @return string
     */
    public function getName() {
        return $this->name;
    }

    /**
     * @param string $name
     */
    public function setName($name) {
        $this->name = $name;
    }

    /**
     * @return string
     */
    public function getSurname() {
        return $this->surname;
    }

    /**
     * @param string $surname
     */
    public function setSurname($surname) {
        $this->surname = $surname;
    }

    /**
     * @return date
     */
    public function getBorn() {
        return $this->born;
    }

    /**
     * @param date $born
     */
    public function setBorn($born) {
        $this->born = $born;
    }

    /**
     * @return smallint
     */
    public function getGender() {
        return $this->gender;
    }

    /**
     * @param smallint $gender
     */
    public function setGender($gender) {
        $this->gender = $gender;
    }

    /**
     * @return text
     */
    public function getAddress() {
        return $this->address;
    }

    /**
     * @param text $address
     */
    public function setAddress($address) {
        $this->address = $address;
    }

    /**
     * @return int
     */
    public function getCountryId() {
        return $this->country_id;
    }

    /**
     * @param int $country_id
     */
    public function setCountryId($country_id) {
        $this->country_id = $country_id;
    }

    /**
     * @return text
     */
    public function getAbout() {
        return $this->about;
    }

    /**
     * @param text $about
     */
    public function setAbout($about) {
        $this->about = $about;
    }

    /**
     * @return string
     */
    public function getInstitution() {
        return $this->institution;
    }

    /**
     * @param string $institution
     */
    public function setInstitution($institution) {
        $this->institution = $institution;
    }

    /**
     * @return text
     */
    public function getAreaOfExpertise() {
        return $this->area_of_expertise;
    }

    /**
     * @param text $area_of_expertise
     */
    public function setAreaOfExpertise($area_of_expertise) {
        $this->area_of_expertise = $area_of_expertise;
    }

    /**
     * @return string
     */
    public function getCvPath() {
        return $this->cv_path;
    }

    /**
     * @param string $cv_path
     */
    public function setCvPath($cv_path) {
        $this->cv_path = $cv_path;
    }

    /**
     * @return string
     */
    public function getFacebookLink() {
        return $this->facebook_link;
    }

    /**
     * @param string $facebook_link
     */
    public function setFacebookLink($facebook_link) {
        $this->facebook_link = $facebook_link;
    }

    /**
     * @return string
     */
    public function getTwitterLink() {
        return $this->twitter_link;
    }

    /**
     * @param string $twitter_link
     */
    public function setTwitterLink($twitter_link) {
        $this->twitter_link = $twitter_link;
    }

    /**
     * @return string
     */
    public function getInstagramLink() {
        return $this->instagram_link;
    }

    /**
     * @param string $instagram_link
     */
    public function setInstagramLink($instagram_link) {
        $this->instagram_link = $instagram_link;
    }

    /**
     * @return string
     */
    public function getLinkedinLink() {
        return $this->linkedin_link;
    }

    /**
     * @param string $linkedin_link
     */
    public function setLinkedinLink($linkedin_link) {
        $this->linkedin_link = $linkedin_link;
    }

    /**
     * @return string
     */
    public function getImgPath() {
        return $this->img_path;
    }

    /**
     * @param string $img_path
     */
    public function setImgPath($img_path) {
        $this->img_path = $img_path;
    }

    /**
     * @return string
     */
    public function getUniversity() {
        return $this->university;
    }

    /**
     * @param string $university
     */
    public function setUniversity($university) {
        $this->university = $university;
    }

    /**
     * @return date
     */
    public function getUniversityGraduatedAt() {
        return $this->university_graduated_at;
    }

    /**
     * @param date $university_graduated_at
     */
    public function setUniversityGraduatedAt($university_graduated_at) {
        $this->university_graduated_at = $university_graduated_at;
    }

    /**
     * @return string
     */
    public function getMd() {
        return $this->md;
    }

    /**
     * @param string $md
     */
    public function setMd($md) {
        $this->md = $md;
    }

    /**
     * @return date
     */
    public function getMdGraduatedAt() {
        return $this->md_graduated_at;
    }

    /**
     * @param date $md_graduated_at
     */
    public function setMdGraduatedAt($md_graduated_at) {
        $this->md_graduated_at = $md_graduated_at;
    }

    /**
     * @return string
     */
    public function getAssociateProfessor() {
        return $this->associate_professor;
    }

    /**
     * @param string $associate_professor
     */
    public function setAssociateProfessor($associate_professor) {
        $this->associate_professor = $associate_professor;
    }

    /**
     * @return date
     */
    public function getAssociateProfessorGraduatedAt() {
        return $this->associate_professor_graduated_at;
    }

    /**
     * @param date $associate_professor_graduated_at
     */
    public function setAssociateProfessorGraduatedAt($associate_professor_graduated_at) {
        $this->associate_professor_graduated_at = $associate_professor_graduated_at;
    }
}
public function getUserByEmailAndPassword($email, $password, $ip, $user_agent) {
        $repository = $this->getEntityManager()->getRepository('App\Entity\Users');
        $user = $repository
            ->createQueryBuilder('u')
            ->addSelect('ui') // to limit queries when doing $user->getUserInformation()
            ->innerJoin('u.userInformation', 'ui')
            ->where('u.email = :email')->setParameter('email', $email)->getQuery()->getSingleResult();

        if ($user == null)
            return 0; // user not found

        $salt = $user->getSalt();
        $encrypted_password = $user->getEncryptedPassword();
        $hash = $this->checkhashSSHA($salt, $password);

        if ($hash == $encrypted_password) {
            return array(
                'id' => $user->getId(),
                'email' => $user->getEmail(),
                'type' => $user->getType(),
                'information' => $user->getUserInformation(),
                'created_at' => $user->getCreatedAt(),
                'updated_at' => $user->getUpdatedAt(),
                'is_deleted' => $user->getIsDeleted()
            );
        }
        return 1; // wrong email or password
    }