Zend Framework Webcast

By Nuno Mariz, on 5 December 2005 @ 21:43
Zend Technologies
php|architect has posted the recorded version of their Zend Framework webcast on their site. I must say is quite impressive. I've been developing a new framework to take advantage of the new features of PHP5. Right now is quite mature and is in prodution, but lacks of some features. One of the features that is missing is the ActiveRecord that Zend will implement in their new framework. Quite curious is the ZMail, have almost the same API of my Mailer class. One of the aspects that im also curious is the ZForms, right now in my framework is quite flexible. I can extend my FormManager class and add the elements that i need, like this:
include_once 'class.FormManager.php';

class FormLogin extends FormManager {
  public function __construct() {
    /*
     * Calling the parent
     * Usage::
     * parent::__construct($name,
     *                     $action = null,
     *                     $method = null,
     *                     $enctype = null,
     *                     $extra = null);
     */
    parent::__construct('FormLogin', null, 'POST', null, null);
  }

  // Must implement this method  
  public function initElements() {
    /*
     * Adding an Hidden Element
     * Usage:
     * $this->addHiddenElement($name, $value);
     */
    $this->addHiddenElement('module', 'Authentication');
    $this->addHiddenElement('action', 'login');

     /*
     * Adding an Element
     * Usage:
     * $this->addElement($type, $name, $label, $options);
     */
    $usernameOptions = array(...)
    $this->addElement('text', 
                      'username',
                      'Username',
                      $usernameOptions);

     /*
     * Adding a Validator
     * Usage:
     * $this->addValidator($elementName, $validatorObject);
     */
    $this->addValidator('username',
                        new RequiredValidator());
    $this->addValidator('username',
                        new MaxLengthValidator(array('length'=>15)));

    $passwordOptions = array(...)
    $this->addElement('password',
                      'password', 
                      'Password',
                      $usernameOptions);

    $loginOptions = array(...);
    $this->addElement('submit', 'login', 'Login', $loginOptions);
  }
}

$form = new FormLogin();
$form->render(); // render HTML form
echo $form->getFormStart();
// show the Username label
echo $form->getElementLabel('username'); 
// show the Username imput
echo $form->getElementInput('username'); 
// show the Password label
echo $form->getElementLabel('password'); 
// show the Password input
echo $form->getElementInput('password'); 
// show the Login submit button
echo $form->getElementInput('login'); // show the Login submit button
echo $form->getFormEnd();
Another way is to load the XML configuration for the form:
include_once 'class.XMLFormManager.php';

$form = new XMLFormManager('FormLogin.xml');
$form->render(); // render HTML form
echo $form->getFormStart();
echo $form->getElementLabel('username'); // show the Username label
echo $form->getElementInput('username'); // show the Username imput
echo $form->getElementLabel('password'); // show the Password label
echo $form->getElementInput('password'); // show the Password input
echo $form->getElementInput('login'); // show the Login submit button
echo $form->getFormEnd();
In the XML way is quicker, i have a web application to generate the XML automatically. I can create or load XML forms and edit with an interface. I can bind elements with database table fields, add and configure validators, etc. Recently i've improved the package to support the binding of an element with a database table field, the syntax is similary but with 2 more parameters in the addElement() method.

Comments

No comments yet.
Comments are closed.