使用 Propel 选择条件选择某些字段
我无法在 Symfony 1.4 中为 Propel Criteria 提供的文档中找到类似的内容
默认情况下,该标准是:
$this->Merchantss = MerchantsPeer::doSelect(new Criteria());
但是,这会选择“商家”表中的所有字段。我只想选择几个,比如:id、名称、类别。如何通过标准来做到这一点?
我尝试了以下操作,但它没有返回输出:
$criteria = new Criteria();
$criteria->add(MerchantsPeer::NAME);
$criteria->add(MerchantsPeer::ID);
$criteria->add(MerchantsPeer::CATEGORY);
$this->Merchantss = MerchantsPeer::doSelect($criteria);
提前致谢
I am unable to find something like this in documentation provided for Propel Criteria in Symfony 1.4
The criteria, by default, is:
$this->Merchantss = MerchantsPeer::doSelect(new Criteria());
However, this selects all the fields in the table for 'Merchants'. I would only like to select a couple, lets say: id, name, category. How is it possible to do so through criteria?
I tried the following but it doesn't return an output:
$criteria = new Criteria();
$criteria->add(MerchantsPeer::NAME);
$criteria->add(MerchantsPeer::ID);
$criteria->add(MerchantsPeer::CATEGORY);
$this->Merchantss = MerchantsPeer::doSelect($criteria);
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
操作方法如下:
$this->MerchantsStmt 是一个
PDOStatement
对象,可以使用->fetch()
方法对其进行迭代。更多详情请参见这里: PDOStatement为了显示模板中的内容,您需要知道 symfony 会“保护”传递给模板的对象内容,以防止恶意代码被执行。如果您信任 $MerchantsStmt 对象的内容,那么您可以像这样迭代它:
This is how to do it:
$this->MerchantsStmt is a
PDOStatement
object, which can be iterated using the->fetch()
method. See here for more details: PDOStatementIn order to display the content in the template, you need to know that symfony 'protects' the content of the object passed to the template to prevent malicious code from being executed. If you trust the content of the $MerchantsStmt object, then you can iterate it like this: