执行期间发生错误;请稍后再试.Zend \ View \ Exception \ RuntimeException

时间:2015-02-13 14:20:39

标签: php zend-framework zend-framework2 zend-form

我已经安装了zend skeleton应用程序框架。安装后运行浏览器它的工作正常。 显示以下页面:

enter image description here

插入module.run后代码也运行良好。

enter image description here

创建以下后创建Registerform。 SRC /用户/窗体/ RegisterForm.php

<?php
// filename : module/Users/src/Users/Form/RegisterForm.php
namespace Users\Form;
use Zend\Form\Form;
class RegisterForm extends Form
{
public function __construct($name = null)
{
parent::__construct('Register');
$this->setAttribute('method', 'post');
$this->setAttribute('enctype','multipart/formdata');
$this->add(array(
'name' => 'name',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Full Name',
),
));
$this->add(array(
'name' => 'email',
'attributes' => array(
'type' => 'email',
),
'options' => array(
'label' => 'Email',
),
'attributes' => array(
'required' => 'required'
),
'filters' => array(
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'EmailAddress',
'options' => array(
'messages' => array(
\Zend\Validator\
EmailAddress::INVALID_FORMAT => 'Email address format is
invalid'
)
)
)
)
));
}
}

注册页面的视图是在 SRC /视图/用户/注册/ index.phtml

<section class="register">
<h2>Register</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'=>'Register', 'action' => 'process')));
$form->setAttribute('method', 'post');
echo $this->form()->openTag($form);
?>
<dl class="zend_form">
<dt><?php echo $this->formLabel($form->get('name')); ?></dt>
<dd><?php
echo $this->formElement($form->get('name'));
echo $this->formElementErrors($form->get('name'));
?></dd>
<dt><?php echo $this->formLabel($form->get('email')); ?></
dt>
<dd><?php
echo $this->formElement($form->get('email'));
echo $this->formElementErrors($form->get('email'));
?></dd>
<dt><?php echo $this->formLabel($form->get('password'));
?></dt>
<dd><?php
echo $this->formElement($form->get('password'));
echo $this->formElementErrors($form->get('password'));
?></dd>
<dt><?php echo $this->formLabel($form->get('confirm_
password')); ?></dt>
<dd><?php
echo $this->formElement($form->get('confirm_password'));
echo $this->formElementErrors($form->get('confirm_
password'));
?></dd>
<dd><?php
echo $this->formElement($form->get('submit'));
echo $this->formElementErrors($form->get('submit'));
?></dd>
</dl>
<?php echo $this->form()->closeTag() ?>
</section>

确认页面的视图非常简单,视图创建于  SRC /视图/用户/注册/ confirm.phtml。

<section class="register-confirm">
<h2>Register Sucessfull</h2>
<p> Thank you for your registration. </p>
</section>

src / Users / Controller / RegisterController.php文件

<?php
namespace Users\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Users\Form\RegisterForm;
class RegisterController extends AbstractActionController
{
public function indexAction()
{
$form = new RegisterForm();
$viewModel = new ViewModel(array('form' =>
$form));
return $viewModel;
}
public function confirmAction()
{
$viewModel = new ViewModel();
return $viewModel;
}
}

配置/ module.config.php:

<?php
return array(
    'controllers' => array(
        'invokables' => array(
            'Users\Controller\Index' => 'Users\Controller\IndexController',
            'Users\Controller\Register' =>'Users\Controller\RegisterController',
        ),
    ),
    'router' => array(
        'routes' => array(
            'users' => array(
                'type'    => 'Literal',
                'options' => array(
                    // Change this to something specific to your module
                    'route'    => '/users',
                    'defaults' => array(
                        // Change this value to reflect the namespace in which
                        // the controllers for your module are found
                        '__NAMESPACE__' => 'Users\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    // This route is a sane default when developing a module;
                    // as you solidify the routes for your module, however,
                    // you may want to remove it and replace it with more
                    // 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(
            'ZendSkeletonModule' => __DIR__ . '/../view',
        ),
    ),
);

最后我希望输出看起来像但我收到错误:    enter image description here

但我收到错误:  执行期间发生错误;请稍后再试。  附加信息:  的Zend \视图\异常\ RuntimeException的

#0 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\View\View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#1 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\View\View.php(233): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#2 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\View\View.php(198): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
#3 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\Mvc\View\Http\DefaultRenderingStrategy.php(103): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#4 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#5 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#6 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('render', Object(Zend\Mvc\MvcEvent), Array)
#7 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(352): Zend\EventManager\EventManager->trigger('render', Object(Zend\Mvc\MvcEvent))
#8 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(327): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))
#9 D:\xampp\htdocs\CommunicationApp\public\index.php(17): Zend\Mvc\Application->run()
#10 {main}

请帮帮我!!!

2 个答案:

答案 0 :(得分:2)

我在本书中遇到了同样的问题。 无论如何,问题是你正在调用

中的“视图”
"src/view/users/register/index.phtml" 

并在config / module.config.php中设置了

    'view_manager' => array(
    'template_path_stack' => array(
        'ZendSkeletonModule' => __DIR__ . '/../view',
    ),
), 

它应指向正确的文件位置 DIR 。的 '/../的src /视图'即可。 或者您应该将此文件夹移动到正确的位置“module / Users / view”(没有“src”),其中所有视图都应该是。

答案 1 :(得分:0)

我从未使用ZfcUser模块,我认为它是......

尝试以下方法:

//In RegisterForm.php remove this 2 lines

$this->setAttribute('method', 'post');
$this->setAttribute('enctype','multipart/formdata');

//In your index.phtml change like this

$form = $this->form;
$form->setAttribute('action', $this->url('yourRouteName', array('action' => 'process')));
$form->prepare();

....