Studyon Minte9.com
ZF 1.0




Overview



#index.php
<?php
	...
	$frontController = Zend_Controller_Front::getInstance();
	$modules = $frontController->getControllerDirectory(); 
		// array('default' => "../Application/modules/default/controllers")
	foreach ($modules as $k => $v) {
		//adding modules to the path
		set_include_path(str_replace(DIRECTORY_SEPARATOR . 'controllers', '', $v) . 
PATH_SEPARATOR . get_include_path());
	}

#modules/default/controllers/FrontendController.php
<?php
	...
	$form = new Forms_Login(); // modules/default/Forms
	$this->view->loginForm = $form;

	if ($this->getRequest()->isPost()) {
		if ( ! $form->isValid($this->getRequest()->getPost())) {
			parent::addMessage('changeFailed');
		} else {
			$dataPOST = $form->getValues();
			...
			$this->_helper->flashMessenger('Success.');  
                        $this->_redirect($_SERVER['SCRIPT_NAME']); // self redirect
		}
	} else {
		if ($form->isErrors()) {
                        $this->view->messages = array('message' => 'Eroare la adaugare data');
		}
	}
	$flm = $this->_helper->getHelper('FlashMessenger'); 
        $this->view->messages = $flm->getMessages();	 


#modules/default/Forms/Login.php
<?php
	class Forms_Login extends Zend_Form {
		
		public function init() {
			
			$username = $this->createElement('text','username');
			$username->setRequired(true);
			$username->setLabel('Username');
			
			$password = $this->createElement('password','password');
			$password->setRequired(true);
			$password->setLabel('Password');

			$submit = new Zend_Form_Element_Submit("submit");
			$submit->setLabel("Submit");

			$this->addElement($username);
			$this->addElement($password); 
			$this->addElement($submit);
		}
	}

#modules/default/views/scripts/frontend/login.phtml
<?php 
	echo $this->loginForm;

	<?php foreach($this->messages as $v): ?>
                        <?php echo $v['message']; ?>
	<?php endforeach; ?>


http://framework.zend.com/manual/en/zend.form.quickstart.html
http://zendframeworkdocumentation.com/classZend__Form.html
http://stackoverflow.com/questions/534870/zend-form-how-do-i-make-it-bend-to-my-will