If I set resultSetPrototype to TableGateway, then $select->columns() not work as expected

https://docs.laminas.dev/tutorials/getting-started/database-and-models/
I learn to start my laminas-db like

If I remove the follow code

$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\ForumMain());

It will affect the form model handling data? I thought it highly involved in form submit logic
https://docs.laminas.dev/tutorials/getting-started/forms-and-actions/

Sometimes I just follow the tutorial and don’t know why, :joy:
Maybe I am not deserve such this framework.

You create a ​result set with your objects Model\ForumMain but then you convert the entire set to array.
The result set Laminas\Db\ResultSet\ResultSet is lost and also the objects from type Model\ForumMain in the result set.
See the method toArray() in your ForumMainTable class.


You can check the SQL query with:

$forumList = $this->tableGateway->select(function (Select $select) {
    // your code
});

echo $forumList->getDataSource()->getResource()->queryString;

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;
}

What do mean with “interface” here?

Our company have an app on android and ios. The app use the interface that I provided. It is a RESUTFUL data flow via an URL. :joy:

This is good, but it does not mean that you have to convert everything in your application to an array. The conversion to JSON or XML is only needed in the output and not internally in your application.