主义和ZF2 [英] Doctrine and ZF2

查看:74
本文介绍了主义和ZF2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用教义连接时遇到麻烦。我无法分享我的代码。但是我可以告诉你情况。
请帮助我实现这一目标。

I am facing trouble using doctrine join. I can't share my code. But I can tell you scenario. Please help me to achieve that.

我创建了2个实体。一个用户和一种语言。

I have created 2 entity. One User and Language.

用户表具有外键language_id。 语言是具有ID和代码字段的主表。

User table is having foreign key language_id. and Language is master table with id and code fields.

我想用一些条件获取用户,例如,它也从语言表中返回语言代码。

I want to fetch user with some criteria, such a way it returns Language code from Language table as well.

我为此编写了join,但是它返回了一些完整的对象...
不知道如何从Language表中获取用户表中设置的language_id的相应语言代码

I write join for that but it returns some full object... Not sure how to fetch corresponding language code from Language table for language_id set in user table

如果有一些示例,您知道可以帮我的忙,那么也可以

If there is some example you know which can help me then also fine

我在__construct()中返回了该示例

i have return this in __construct()

 $this->languageObj = new ArrayCollection();

在我们打印时,给出的是这个

when we print it is gives this

 [languageObj:User:private] => Common\User\Entity\Language Object
            (
                [languageId:Language:private] => 1
                [languageCode:Language:private] => en
                [languageName:Language:private] => English
                [languageCode2:Language:private] => User Object

RECURSION

我无法从对象中获取languageCode

I am not able to fetch languageCode from the object

推荐答案

您需要在实体中定义的方法才能从对象返回值。似乎一切正确,您只需要从实体中获取价值即可。下面是一个示例:

You need methods defined in your entity to return the value from the object. It seems like everything is correct you would just need to grab the value from the entity. Here is an example:

$userEntity->getLanguageObj()->getLanguageId();

您的用户实体需要使用getLanguageObj方法,您可以这样定义它:

Your user Entity would need the getLanguageObj method which you can define like this:

public function getLanguageObj() {
     return $this->languageObj;
}

您的语言实体也需要getLanguageId方法:

And your Language Entity would also need a getLanguageId method:

public function getLanguageId() {
     return $this->languageId;
}

希望有帮助!

这篇关于主义和ZF2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆