zf2 tablegateway select columns by column name

こ雲淡風輕ζ 提交于 2019-12-10 23:56:06

问题


<code> 
$resultSet = $this->tableGateway->select ( function ($select) {
$select->columns ( 
        array (
        'id',
        'category_name' 
) );

} );

tried with above code but it returning all columns, below is the output of return. I need to select id and category_name from database

Category\Model\Category Object ( [id] => 2 [category_name] => Cat Two [category_created] => [category_status] => [inputFilter:protected] => ) Category\Model\Category Object ( [id] => 4 [category_name] => Cat one [category_created] => [category_status] => [inputFilter:protected] => )


回答1:


I had this problem. I think it might be because the function is being ignored inside the first select function and it just just returning everything. I found a way to get this to work, try something like the following:

Use the Select class along with the selectWith function of the tablegateway:

use Zend\Db\Sql\Select as Select;

$select = new Select();
$select->from('table');
$select->columns(array('id','category_name'));

$resultSet = $this->tableGateway->selectWith($select);


来源:https://stackoverflow.com/questions/21965603/zf2-tablegateway-select-columns-by-column-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!