Kohana 简单地从数据库读取

发布于 2024-10-17 11:10:22 字数 519 浏览 3 评论 0原文

我正在尝试从数据库中检索一些简单的数据,但我不知道我错在哪里。

我想从我的数据库中获取所有非活动用户。为此,我在控制器:

    public function action_useremails()
{   
    $users = Model::factory('user')->where('user_status', '=', 2);  
    $this->view->users = $users;
}

和视图中:

 <? foreach ($users as $user): ?>
    <tr>
        <td><span><?= $user; ?></span></td>

    </tr>
<? endforeach; ?>

但即使我有不活动的用户,我在视图中也看不到任何内容。我想知道我哪里错了? }

i am trying to retrieve some simple data from the database, and i don't know where i am wrong.

i want to get all the inactive users from my database. For that, i have in my controller:

    public function action_useremails()
{   
    $users = Model::factory('user')->where('user_status', '=', 2);  
    $this->view->users = $users;
}

and in the view:

 <? foreach ($users as $user): ?>
    <tr>
        <td><span><?= $user; ?></span></td>

    </tr>
<? endforeach; ?>

butm even though i have inactive users, i don't see anything in the view. I wonder where am i wrong?
}

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

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

发布评论

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

评论(3

剪不断理还乱 2024-10-24 11:10:22

您正在构建查询,但没有执行它。尝试:

$this->view->users = $users->execute();

还考虑视图中的 $users 变量将是数组的数组,您必须回显正确的元素。

You're building the query, but not executing it. Try:

$this->view->users = $users->execute();

also consider that the $users variable in the view will be an array of arrays, you'll have to echo the right element.

枉心 2024-10-24 11:10:22

如果您正在谈论 Kohana 2,您的查询必须是:

$users = Model::factory('user')->where('user_status', 2)->find();

注意 where() 块中的参数 &最后找到find()。如果没有 find(),您只是构建查询,而不是运行它。

文档: http://docs.kohanaphp.com/libraries/orm#find

如果是是KO​​3,肯定和上面类似。

If you are talking about Kohana 2, your query must be:

$users = Model::factory('user')->where('user_status', 2)->find();

Note the args in where() block & the find() at last. Without find(), you are just building the query, but not running it.

Docs: http://docs.kohanaphp.com/libraries/orm#find

If it is KO3, it has to be similar to the above.

可是我不能没有你 2024-10-24 11:10:22

对于 v3.0,在末尾添加 find_all() 方法:

$users = Model::factory('user')->where('user_status', '=', 2)->find_all();

它执行您之前使用其他方法构建的查询。

for v3.0 add the find_all() method at the end:

$users = Model::factory('user')->where('user_status', '=', 2)->find_all();

It executes the query you built before with the other methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文