Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.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_Symfony1_Foreign Keys_Foreign Key Relationship_Propel - Fatal编程技术网

Php 如何使用外键关系从数据库检索列?

Php 如何使用外键关系从数据库检索列?,php,symfony1,foreign-keys,foreign-key-relationship,propel,Php,Symfony1,Foreign Keys,Foreign Key Relationship,Propel,我有一个user表,它存储了他的所有信息,我还通过schema.yml创建了一个名为user\u education的表。[uid此表中的列指的是user表的uid]。模型类是使用Symfony创建的。我能够访问user表的所有列。例如sf_user->getUser()->getUsername() 用户模型类还有一个方法,getUserEducations()。我需要访问user_education table中名为coursename的列,但无法访问。目前,我正在尝试[sf_user->g

我有一个user表,它存储了他的所有信息,我还通过schema.yml创建了一个名为user\u education的表。[uid此表中的列指的是user表的uid]。模型类是使用Symfony创建的。我能够访问user表的所有列。例如sf_user->getUser()->getUsername()

用户模型类还有一个方法,getUserEducations()。我需要访问user_education table中名为coursename的列,但无法访问。目前,我正在尝试[sf_user->getUser()->getUserEducations()->getCoursename();]但是我得到了整个记录数组。我无法通过该数组检索单个列

如何检索它?

您可以通过以下方式进行检索:

// get the first tuple
$sf_user->getUser()->getUserEducations()->getFirst()->getCoursename();

正确的方法(如果用户受过很多教育)是在实例之间迭代:

foreach($sf_user->getUser()->getUserEducations() as $education){
    //do something with like
    echo $education->getCoursename();
}
foreach($sf_user->getUser()->getUserEducations() as $education){
    //do something with like
    echo $education->getCoursename();
}