开发者

Display Form with Zend

开发者 https://www.devze.com 2023-04-12 12:10 出处:网络
I need a simple way to display this form. The reason why im doing it this way is to see how things can be passed from one controller to another controller and displaying those things. Im learning Zend

I need a simple way to display this form. The reason why im doing it this way is to see how things can be passed from one controller to another controller and displaying those things. Im learning Zend right now but its been quite frustrating. This is stuff from the zend tutorial. I want to IndexController to redirect to Guestbook and Guestbook to create the form and go to the view.

This is my folder structure

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->redi开发者_JS百科rector('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;          
    } 

}

Stacktrace

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号