2014-09-29 59 views
0

無法呈現zf2中的文件錯誤。
我正在爲一個婚姻網站項目工作,在這個項目中,我需要根據匹配的要求搜索數據,但得到一個錯誤。 這裏是我的代碼:Zend View Renderer PhpRenderer :: render:無法呈現模板

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

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')); 
?> 
&nbsp;&nbsp;<b>to </b>&nbsp;&nbsp; 
<?php echo $this->formElement($form->get('ageto')); 
?></td></tr> 
<tr><th>Height:</th> 
<td><?php 
echo $this->formElement($form->get('heightfrom')); 
?> 
&nbsp;&nbsp;<b>to</b> &nbsp;&nbsp; 
<?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: Unable to render template "project/search/process"; resolver could not resolve to a file

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', 
    ), 




), 
); 

回答

2

您是否創建了文件Project/view/project/search/process.phtml?

+0

否我的文件爲Project/view/project/search/index.phtml和Project/view/project/search/confirm.phtml – prachi 2014-09-29 06:53:09

+0

無法呈現模板「project/search/process」 - 錯誤清楚地告訴你process.phtml丟失! – webDEVILopers 2014-09-29 07:12:26

+0

但我必須通過processAction和confirmAction方法呈現confirm.phtml,而不是process.phtml – prachi 2014-09-30 05:41:55

相關問題