Tag: zend framework2

在select tag(view)中显示json值zend框架2

我的模型:从数据库中获取数据 public function getAllProjectDomain() { $dbadapter = $this->adapter; $sql = new Sql($dbadapter); $select = $sql->select(); $select->columns(array(‘cmain’)); $select->from(‘projcat’); $selectString = $sql->getSqlStringForSqlObject($select); $result = $dbadapter->query($selectString, $dbadapter::QUERY_MODE_EXECUTE); foreach ($result as $row) { $entity = array( “domain” => $row->cmain ); $entities[] = $entity; } return $entities; } 我的控制器: public function domainAction() { if ($this->getRequest()->isPost()) { $service = $this->getServiceLocator()->get(‘UserService’); $result […]

如何在确认弹出窗口中使用zend delete动作?

我想使用确认弹出窗口删除我的项目,所以这是我的删除操作: public function deleteAction() { $id = (int) $this->params()->fromRoute(‘id’, 0); $article = $this->getObjectManager()->find(‘\Application\Entity\Article’, $id); if ($this->zfcUserAuthentication()->hasIdentity()) { if ($this->request->isPost()) { $this->getObjectManager()->remove($article); $this->getObjectManager()->flush(); return $this->redirect()->toRoute(‘blog’); } } else { return $this->redirect()->toRoute(‘user’); } return new ViewModel(array(‘article’ => $article)); } 这是我的博客视图,我有删除链接: <a href="https://stackoverflow.com/questions/21991035/how-to-use-zend-delete-action-in-confirmation-popup/url(‘delete’, array(‘action’=>’delete’, ‘id’ => $articles->getId())) ?>” class=”btn btn-default btn-lg” onclick=”if (confirm(‘Are you sure?’)) { document.location = […]

如何在zend框架2或AjaxContext中使用ajax?

AjaxContext助手在ZF1中是一个很好的function,我在很多地方使用它。 我想知道这是否在ZF2中可用。 我做了一个测试,并补充说: public function init() { $ajaxContext = $this->_helper->getHelper(‘AjaxContext’); $ajaxContext->addActionContext(‘input’, ‘html’) ->addActionContext(‘number’, ‘html’) ->initContext(); } 在控制器中,添加了一个动作: public function inputAction() { $form = new AddInput(); return [‘form’ => $form]; } 文件input.ajax.phtml 和ajax调用: $.get(‘/form/input/format/html’).css(“display”,”block”); 请求通过ok,使用200代码,但我得到渲染错误 Fatal error: Uncaught exception ‘Zend\View\Exception\RuntimeException’ with message ‘Zend\View\Renderer\PhpRenderer::render: Unable to render template “form/index/input”; resolver could not resolve to a file’ in […]

如何将外部javascript文件添加到Zend Framework 2应用程序?

我需要将jQuery和其他javascript文件添加到我的Zend Framework项目中。 我正在尝试使用Action控制器: – public function userinfoAction() { $this->view->headScript()->appendFile($basePath .’/js/validate_jquary.js’); $this->headScript()->appendFile(‘http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js’); return new ViewModel(); } 但它没有用。