我想在视野中扼杀结果。问题是它没有精确的工作。缺什么?我阅读了文档,但他们没有给出完整的ansver如何通过cusotm查询检索数据。对我来说,作为一个beinnger很难说下一步做什么?我的意思是这个查询我知道如何通过viewmodel等传递给它。请帮助。
$config = $this->getServiceLocator()->get('config');
$adapter = new \Zend\Db\Adapter\Adapter($config[db]);
$sql = new Sql($adapter);
$select = $sql->select();
$select->from('brokerzy');
$select->where(array('broker_status' => 'publish'));
$stm = $sql->prepareStatementForSqlObject($select);
$results = $stm->execute();
答案 0 :(得分:0)
首先,您可能不应该在您的控制器中进行查询,这是不好的做法。应将这些查询移到服务接口后面。
但是,要回答您的问题(如果我理解的话),要将查询结果传递给视图,您应该使用视图模型。它看起来像这样。
//Your Code
$results = $stm->execute();
$viewModel = new \Zend\View\Model\ViewModel();
$viewModel->results = $results;
return $viewModel;