Zend 框架 - Zend_db_table_abtract select()
我想使用 select()
,我可以在不指定表名的情况下只获取一列。 (表名位于我的模型中声明的 $_name var 中。)我尝试了以下操作:
$select->columns('field');
.. 但出现“没有为 FROM 子句指定表”的错误 - 所以看起来它需要一个表名。
有没有办法只获取一列?
I want to use select()
where I can get just one column without specifying the table name. (Table name is in the $_name var declared in my model.) I tried this:
$select->columns('field');
.. but I get error of "No table has been specified for the FROM clause" - so it looks like it's expecting a table name.
Is there a way of getting just one column?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误是正确的。您需要指定一个想要从中获取字段的表。
The error is correct. You need to specify a table you want the field from.
如果您的类扩展了
Zend_Db_Table_Abstract
,您可以使用$this->fetchAll()
,因此不需要指定表名。如果您仍然想使用
select()
,请传递$this->_name
因为您已经声明了值$_name
。select()
主要用于创建一个选择查询对象,因此尽管当前您位于模型中,但它无法猜测您要从哪个表中查找。它可能不适用于对同一个表的查询。所以你应该传递表名。有关更多信息,请参见 http://framework.zend.com/manual/en/ zend.db.select.html 。一切都是为了不同的目的。所以你要根据你的意愿来使用。If your class extends the
Zend_Db_Table_Abstract
, you can use$this->fetchAll()
, so no table name need to be specified.If you still want to use
select()
pass the$this->_name
as you have already declared the value$_name
.select()
is mainly used to create a select query object, so it cannot guess from which table you are going to though currently you are in the model. It may not be for a query on the same table. So you should pass the table name. For more see http://framework.zend.com/manual/en/zend.db.select.html . All are for different purposes. So you want to use according to your wish.