如何使用 CI 中的 datamapper 从当前模型获取另一个模型中的相关字段?

发布于 2024-10-07 11:13:08 字数 110 浏览 0 评论 0原文

我是 CodeIgniter 和 DataMapper 的新手用户。我有一个用户模型和用户组模型。这两种模型都具有一对多的关系。有什么方法可以使用用户模型在用户组中获取 user_group_name 吗?

I am a newbie user to CodeIgniter and DataMapper. I have a User model and User Group model. Both of this model has an one-to-many relationships. Is there any way I could get user_group_name in User Group using the User model?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

画离情绘悲伤 2024-10-14 11:13:08

首先阅读 http://datamapper.exitecms.org 上的 Datamapper 用户指南。

您可以使用 include_lated() 将相关模型中的列包含到结果中。

Start by reading the Datamapper user guide, on http://datamapper.exitecms.org.

You can include columns from a related model into the result by using include_related().

夜清冷一曲。 2024-10-14 11:13:08

您应该首先熟悉 codeigniter。

至于你的问题,我认为你最好从 datamapper 论坛或 codeigniter 论坛获得帮助。

You should familiarize yourself with codeigniter first.

As for your question, I think it would be better for you to get help from the datamapper forums or the codeigniter forums.

冰葑 2024-10-14 11:13:08

万法师和索普,
谢谢你们俩。我已经找到解决方案了。我只从用户模型中调用组模型。下面的代码可以解释它。

<?php 
    foreach($users->all as $user)
    {
        $user->group->get();
    }
?>

Wanwizard and Thorpe,
Thanx for both of you. I have got the solution. I only call Group model from User model. The following code would explain it.

<?php 
    foreach($users->all as $user)
    {
        $user->group->get();
    }
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文