02/09/08

What’s new in Zend framework 1.6

Wildfire, captcha and dojo integration are just some of the highlights.

“Watch this presentation to hear the entire Zend Framework team talk about what to expect from Zend Framework 1.6, soon to be released.
Presented by Wil Sinclair, Development Manager, Matthew Weier O’phinney, Software Architect, Alexander Veremyev, Software Engineer and Ralph Schindler, Software Engineer. – Zend

Click here to download the presentation slides

Click here to watch the recorded Webinar

01/09/08

Zend_Acl and MVC

Quickstart Screencasts

Zend_Auth
Zend_Acl

Zend Developer Zone Tutorials

Zend_Acl and MVC Integration Part I (Basic Use)
Zend_Acl and MVC Integration Part II (Advanced Use)

Matthew Weier O’Phinney Tutorial

Login and Authentication with Zend Framework

Zend_Auth does a lot of behind the scenes work to make persisting an identity in the session trivial. Combine it with Zend_Form, and you have a very easy to implement solution for retrieving and validating credentials; add standard hooks in the Zend_Controller component for filtering actions prior to dispatch, and you can restrict access to applications easily based on authentication status.”

Zend

Zend framework Webinars

Zend_Auth helps web developers to implement authentication for their applications by providing a simple API and various adapters for popular authentication backends, such as LDAP, InfoCard, and OpenID. In this webinar, we implemented the authentication process using Zend_Auth and demonstrate its flexibility and extensibility for custom functionality.”

30/08/08

Populate a Zend_Form select with database returned data

The code speaks for itself:

$category = new Zend_Form_Element_Select('category');
$category->setLabel('Category')
         ->setRequired(true);
 
$table = new Category();
foreach ($table->fetchAll() as $c) {
    $category->addMultiOption($c->id, $c->name);
}

“By default, this element registers an InArray validator which validates against the array keys of registered options. You can disable this behavior by either calling setRegisterInArrayValidator(false), or by passing a false value to the registerInArrayValidator configuration key.”
Zend framework Manual.

If you want to order the way the categories are displayed you could do this in your model.

The database table:

CREATE TABLE IF NOT EXISTS `category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(128) collate utf8_unicode_ci NOT NULL,
  `order` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;
 
INSERT INTO `category` (`id`, `name`, `order`) VALUES
(1, 'Category Three Order 3rd', 3),
(2, 'Category One Order 1st', 1),
(3, 'Category Two Order 2nd', 2);

The model:

< ?php
/** Zend_Db_Table_Abstract */
require_once 'Zend/Db/Table/Abstract.php';
 
class Category extends Zend_Db_Table_Abstract
{
    protected $_name = 'category';
 
    public function findForSelect()
    {
    	$select = $this->select();
    	$select->order('order');
    	return $this->fetchAll($select);
    }
}

Populate the select:

$category = new Zend_Form_Element_Select('category');
$category->setLabel('Category')
         ->setRequired(true);
 
$table = new Category();
foreach ($table->findForSelect() as $c) {
    $category->addMultiOption($c->id, $c->name);
}

28/08/08

Good OOP Practice / Zend framework

An interesting post on nabble yesterday by Matthew Weier O’Phinney on the difference between:

if ($this->getRequest()->isPost()) {
     // process
}
 
if ($this->_request->isPost()) {
     // process
}
 
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // process
}

Sometimes, he explains

“the obvious and simple solutions simply are not portable, or would circumvent custom logic the developer may need to utilize.”

You could use $this->_request

“However, if you ever modify getRequest() in your class or in a custom base controller class, then you may be accessing the wrong property or overriding necessary business logic. For this reason, we recommend using getRequest() to grab the request object.”

“Next, using isPost() is more portable than using $_SERVER['REQUEST_METHOD']. The reasons are that your web server may or may not populate this environment variable, and for testing. With testing, we allow you to specifically set the request method — $_SERVER is never modified in this case. This gives you the ability to test your applications without needing a web server involved.”