我需要一种简单的方法来显示这个表单。我这样做的原因是看看事情如何从一个控制器传递到另一个控制器并显示这些东西。我现在正在学习Zend但是它非常令人沮丧。这是zend教程中的内容。我想让IndexController重定向到Guestbook和Guestbook来创建表单并转到视图。
这是我的文件夹结构
test
-Form
Guestbook.php
-Model
-controllers
GuestbookController.php
IndexController.php
-externals
-Settings
-views
-scripts
-guestbook
script.tpl
sign.tpl
-index
index.tpl
Bootstrap.php
Guestbook.php
<?php
class Test_Form_Guestbook extends Zend_Form{
public function init(){
$this->setMethod('post');
$this->addElement('text','email',array(
'label' => 'Your Email address: ',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array('EmailAddress',)
));
$this->addElement('text','comment',array(
'label' => 'Leave a Comment: ',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
array('validator' => 'StringLength', 'options' => array(0, 20))
)
));
$this->addElement('hash','csrf',array('ignore'=>true,));
}
}
?>
sign.tpl
<?php
$this->form->setAction($this->url());
echo $this->form;
?>
IndexController.php
class Test_IndexController extends Core_Controller_Action_Standard
{
public function indexAction()
{
$this->_helper->redirector('sign', 'guestbook');
}
}
GuestbookController.php
class Test_GuestbookController extends Zend_Controller_Action{
public function signAction(){
$request = $this->getRequest();
$form = new Test_Form_Guestbook();
if($this->getRequest()->isPost()){
if($form->isValid($request->getPost())){
return $this->_helper->redirector('index');
}
}
$this->view->form = $form;
}
}
堆栈跟踪
exception 'Zend_View_Exception' with message 'script '.tpl' not found in path (C:\xampp\htdocs\application\modules\Core\layouts\scripts\;C:\xampp\htdocs\application\modules\Test\views\scripts\;C:\xampp\htdocs\)' in C:\xampp\htdocs\application\libraries\Zend\View\Abstract.php:928
Stack trace:
0 C:\xampp\htdocs\application\libraries\Zend\View\Abstract.php(831): Zend_View_Abstract->_script('.tpl')
1 C:\xampp\htdocs\application\libraries\Zend\Layout.php(793): Zend_View_Abstract->render('.tpl')
2 C:\xampp\htdocs\application\libraries\Zend\Layout\Controller\Plugin\Layout.php(142): Zend_Layout->render()
3 C:\xampp\htdocs\application\libraries\Zend\Controller\Plugin\Broker.php(331): Zend_Layout_Controller_Plugin_Layout->postDispatch(Object(Zend_Controller_Request_Http))
4 C:\xampp\htdocs\application\libraries\Zend\Controller\Front.php(957): Zend_Controller_Plugin_Broker->postDispatch(Object(Zend_Controller_Request_Http))
5 C:\xampp\htdocs\application\modules\Core\Bootstrap.php(75): Zend_Controller_Front->dispatch()
6 C:\xampp\htdocs\application\libraries\Engine\Application.php(99): Core_Bootstrap->run()
7 C:\xampp\htdocs\application\index.php(177): Engine_Application->run()
8 C:\xampp\htdocs\index.php(24): include('C:\xampp\htdocs...')
9 {main}