Thank you!
$forumList = $this->tableGateway->select(function (Select $select){
$predicate = new Predicate();
$predicate->equalTo('valid',1);
$select->columns(['id','classid','name','icon','bgcolor']);
$select->where($predicate);
$select->order('uptime desc');
});
echo $forumList->getDataSource()->getResource()->queryString;exit;
the output
SELECT `forum_main`.`id` AS `id`, `forum_main`.`classid` AS `classid`, `forum_main`.`name` AS `name`, `forum_main`.`icon` AS `icon`, `forum_main`.`bgcolor` AS `bgcolor` FROM `forum_main` WHERE (`valid` = :where1) ORDER BY `uptime` DESC
so it all because ->toArray() method?!!! I am so shocked!
But I am writing a interface for our app, it is hard to handle if the result is an object. I need to transfer it into an array.
No, I tried
foreach ($forumList as $one)
{
print_r($one);exit;
}
It shows all the colums of the table. That’s not I want.
Now I have to change from
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\ForumMain());
return new TableGateway('forum_main', $dbAdapter, null, $resultSetPrototype);
to
$dbAdapter = $container->get(AdapterInterface::class);
return new TableGateway('forum_main', $dbAdapter, null, null);
I can not figure out other ways. I pray that it won’t raise error when I submit my form data via the toturial like Forms and Actions - tutorials - Laminas Docs
I wrote a function to transfer objectList to Array list
public function selectResults2ArrayWithColumnsLimits($selectObjectResults, $columnsArr)
{
$sortedArr = [];
foreach ($selectObjectResults as $objectOne)
{
$tmpArr = [];
foreach ($columnsArr as $columnStr)
{
if (isset($objectOne->$columnStr)) $tmpArr[$columnStr] = $objectOne->$columnStr;
}
$sortedArr[] = $tmpArr;
}
return $sortedArr;
}