Kohana 简单地从数据库读取
我正在尝试从数据库中检索一些简单的数据,但我不知道我错在哪里。
我想从我的数据库中获取所有非活动用户。为此,我在控制器:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在构建查询,但没有执行它。尝试:
还考虑视图中的
$users
变量将是数组的数组,您必须回显正确的元素。You're building the query, but not executing it. Try:
also consider that the
$users
variable in the view will be an array of arrays, you'll have to echo the right element.如果您正在谈论 Kohana 2,您的查询必须是:
注意 where() 块中的参数 &最后找到find()。如果没有 find(),您只是构建查询,而不是运行它。
文档: http://docs.kohanaphp.com/libraries/orm#find
如果是是KO3,肯定和上面类似。
If you are talking about Kohana 2, your query must be:
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.
对于 v3.0,在末尾添加 find_all() 方法:
它执行您之前使用其他方法构建的查询。
for v3.0 add the find_all() method at the end:
It executes the query you built before with the other methods.