Estoy siguiendo un manual, para crear un formulario en Zend, y algún punto me he perdido que no me sale. Tengo instalado Zend y me funciona bien, con todos los directorios.
mi estructura es
quickstart
-aplication
--config
--layouts
--modules
---default
----controller
----models
----views
-----helpers
-----scripts
-docs
-library
-public
Hasta ahora todo funciona bien, pero voy con el formulario.
Creo en el directorio aplication, el directorio forms y dentro el archivo Contact.php, con este código según el manual:
Código PHP:
<?php
class Application_Form_Contact extends Zend_Form
{
public function init ()
{
// initialize form
$this->setAction('/contact/index')->setMethod('post');
// create text input for name
$name = new Zend_Form_Element_Text('name');
$name->setLabel('Name:')
->setOptions(array('size' => '35'))
->setRequired(true)
->addValidator('NotEmpty', true)
->addValidator('Alpha', true)
->addFilter('HTMLEntities')
->addFilter('StringTrim');
// create text input for email address
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email address:');
$email->setOptions(array('size' => '50'))
->setRequired(true)
->addValidator('NotEmpty', true)
->addValidator('EmailAddress', true)
->addFilter('HTMLEntities')
->addFilter('StringToLower')
->addFilter('StringTrim');
// create text input for message body
$message = new Zend_Form_Element_Textarea('message');
$message->setLabel('Message:')
->setOptions(array('rows' => '8', 'cols' => '40'))
->setRequired(true)
->addValidator('NotEmpty', true)
->addFilter('HTMLEntities')
->addFilter('StringTrim');
// create captcha
$captcha = new Zend_Form_Element_Captcha('captcha',
array(
'captcha' => array('captcha' => 'Image', 'wordLen' => 6,
'timeout' => 300, 'width' => 300, 'height' => 100)));
$captcha->setLabel('Verification code:');
// create submit button
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Send Message')->setOptions(
array('class' => 'submit'));
// attach elements to form
$this->addElement($name)
->addElement($email)
->addElement($message)
->addElement($captcha)
->addElement($submit);
}
}
Código PHP:
<?php
/**
* ConctactController
*
* @author
* @version
*/
require_once 'Zend/Controller/Action.php';
class ConctactController extends Zend_Controller_Action
{
/**
* The default action - show the home page
*/
public function init ()
{
$this->view->doctype('XHTML1_STRICT');
}
public function indexAction ()
{
$form = new Application_Form_Contact();
$this->view->form = $form;
if ($this->getRequest()->isPost()) {
if ($form->isValid($this->getRequest()
->getPost())) {
$values = $form->getValues();
$mail = new Zend_Mail();
$mail->setBodyText($values['message']);
$mail->setFrom($values['email'], $values['name']);
$mail->addTo('[email protected]');
$mail->setSubject('Contact form submission');
$mail->send();
$this->_helper->getHelper('FlashMessenger')->addMessage(
'Thank you. Your message was successfully
sent.');
$this->_redirect('/contact/success');
}
}
}
}
Código PHP:
<h2>Contact</h2>
<?php echo $this->form; ?>
Código:
pongo la url : resources.router.routes.contact.route = /contact resources.router.routes.contact.defaults.module = default resources.router.routes.contact.defaults.controller = contact resources.router.routes.contact.defaults.action = index
Código:
y me da el siguiente error:http://localhost/contact
Código:
A ver si alguien puede ayudarme con este problema.An error occurred Page not found Exception information: Message: Invalid controller specified (contact) Stack trace: #0 C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() #2 C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #3 C:\xampp\htdocs\quickstart\public\index.php(26): Zend_Application->run() #4 {main} Request Parameters: array ( 'module' => 'default', 'controller' => 'contact', 'action' => 'index', )
Saludos