0
votes

Unable to render file error in zf2.
I am working on a project for matrimonial site, in which I need to search data according to matched requirement but get an error. Here is my code:

//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 in Project/view/project/search

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

But after clicking on submit I'm getting the renderer error:

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




),
);
1

1 Answers

2
votes

Do you create file Project/view/project/search/process.phtml?