无法在zf2中呈现文件错误。
我正在为婚姻网站开发一个项目,我需要根据匹配的要求搜索数据但是会收到错误。
这是我的代码:
//SearchController.php in Project/src/Project/Controller
public function processAction()
{
if (!$this->request->isPost()) {
return $this->redirect()->toRoute(NULL ,
array( 'controller' => 'search',
'action' => 'index'
));
}
$post = $this->request->getPost();
$dbAdapter=$this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
$form = new SearchForm($dbAdapter);
//$inputFilter = new RegisterFilter();
//$form->setInputFilter($inputFilter);
$form->setData($post);
if (!$form->isValid()) {
$model = new ViewModel(array(
'error' => true,
'form' => $form,
));
$model->setTemplate('project/search/index');
return $model;
}
$ageto = $this->getRequest()->getPost('ageto');
$agefrom = $this->getRequest()->getPost('agefrom');
$heightfrom = $this->getRequest()->getPost('heightfrom');
$heightto = $this->getRequest()->getPost('heightto');
$educationid = $this->getRequest()->getPost('educationid');
$cityid = $this->getRequest()->getPost('cityid');
$complexionid = $this->getRequest()->getPost('complexionid');
$religioncode = $this->getRequest()->getPost('religioncode');
$sql="SELECT * FROM projects WHERE YEAR(CURDATE())-YEAR(dob) BETWEEN ".$agefrom. " AND ".$ageto;
$sql.=" and heightcode BETWEEN ". $heightfrom." AND ". $heightto." and religioncode = ".$religioncode;
$sm = $this->getServiceLocator();
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$statement = $dbAdapter->query($sql);
$result = $statement->execute();
$num=count($result);
if($num==0)
{
echo "No Matches Found";
}
else
{
$result = $statement->execute();
$selectData = array();
foreach ($result as $res) {
$selectData=$res;
}
return $selectData;
}
return $this->redirect()->toRoute(NULL , array(
'controller' => 'search',
'action' => 'confirm'
));
}
public function confirmAction()
{
$viewModel = new ViewModel();
return $viewModel;
}
Project / view / project / search 中的index.phtml
<html>
<head><link rel="stylesheet" href="/css/demo.css" type="text/css" ></head>
<section class="search">
<p> Welcome! </p>
<h2>Search Form</h2>
<?php if ($this->error): ?>
<p class="error">
There were one or more issues with your submission.
Please correct them as
indicated below.
</p>
<?php endif ?>
<?php
$form = $this->form;
$form->prepare();
$form->setAttribute('action', $this->url(NULL,array('controller'=>'Search', 'action' =>'process')));
$form->setAttribute('method', 'post');
$form->setAttribute('enctype','multipart/form-data');
echo $this->form()->openTag($form);
?>
<body>
<div align="left">
<table align="left" cellpadding="6">
<tr><th>Age:</th>
<td><?php
echo $this->formElement($form->get('agefrom'));
?>
<b>to </b>
<?php echo $this->formElement($form->get('ageto'));
?></td></tr>
<tr><th>Height:</th>
<td><?php
echo $this->formElement($form->get('heightfrom'));
?>
<b>to</b>
<?php echo $this->formElement($form->get('heightto'));
?></td></tr>
<tr><th>Education:</th>
<td><?php
echo $this->formElement($form->get('educationid'));
echo $this->formElementErrors($form->get('educationid'));?></td></tr>
<tr><th>City:</th>
<td><?php
echo $this->formElement($form->get('cityid'));
echo $this->formElementErrors($form->get('cityid'));?></td></tr>
<th>Complexion:</th>
<td><?php
echo $this->formElement($form->get('complexionid'));
echo $this->formElementErrors($form->get('complexionid'));?></td></tr>
<tr><th>Religion:</th>
<td><?php
echo $this->formElement($form->get('religioncode'));
echo $this->formElementErrors($form->get('religioncode'));?></td></tr>
<tr>
<td><?php
echo $this->formElement($form->get('submit'));
echo $this->formElementErrors($form->get('submit'));
?></td></tr>
<?php echo $this->form()->closeTag() ?>
</table>
</section>
</div>
但点击提交后我收到渲染器错误:
Zend \ View \ Renderer \ PhpRenderer :: render:无法渲染模板&#34; project / search / process&#34 ;;解析器无法解析为文件
Module.config.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'Project\Controller\Index' =>
'Project\Controller\IndexController',
'Project\Controller\Register' =>
'Project\Controller\RegisterController',
'Project\Controller\Login' =>
'Project\Controller\LoginController',
'Project\Controller\Search' =>
'Project\Controller\SearchController',
),
),
'router' => array(
'routes' => array(
'project' => array(
'type' => 'Literal',
'options' => array(
'route' => '/project',
'defaults' => array(
'__NAMESPACE__' => 'Project\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// specific routes.
'default' => array(
'type' => 'Segment',
'options' => array(
'route' =>
'/[:controller[/:action]]',
'constraints' => array(
'controller' =>
'[a-zA-Z][a-zA-Z0-9_-]*',
'action' =>
'[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'project' => __DIR__ . '/../view',
),
'strategies' => array(
'ViewJsonStrategy',
),
),
);
答案 0 :(得分:2)
你创建文件Project / view / project / search / process.phtml吗?