CakePHP - Simple User Registration

After doing some initial readings on different PHP frameworks, including CakePHP, CodeIgniter, Symphony, Zend. I'm digging deeper into CakePHP with an open eyes for fresh ideas and other developments. To start, CakePHP is slow, quite slow (backed up by Rasmus's benchmark at froscon). It also has not taken advantage of more object-oriented syntax and methods. That said, there are many neat ideas in CakePHP that we can learn to incorporate into our in-house high performance framework (but with less features and automagic).

Framework Performance
To those who says that "slow frameworks is acceptable or understandable": good framework scales both in term of performance and functionality. It should be easily extensible from its tiny core. Software that does not use any framework cannot scale to provide more functionality and can offer good performance only at a simple task. Enough rants, let's get dirty.

First App
This is a simple user registration. Cake does have its way of doing things and you might or might not like it. I'm not a big fan of $validate, $uses, and such. I do hope CakePHP will use more PHP5 and OOP the sooner the better since it's a good framework.

User Model

<?php
/**
* @author Son Nguyen
* @since 12/16/2008
* @package PeerUptime
* @subpackage User
*/
class User extends AppModel {
var $validate = array(
'username' => array('rule' => 'alphaNumeric','required' => true),
'password' => array('rule' => 'alphaNumeric','required' => true),
'password_confirm' => array('rule' => array('validateConfirmPassword'),'message'=>'Mismatch'),
);

/** validate only run through Model->save() or Model->validates() */
function validateConfirmPassword($data) {
if ($this->data['User']['password'] == AuthComponent::password($this->data['User']['password_confirm'])) {
return true;
} // fi
return false;
}

/** check username taken or not */
function beforeValidate() {
if (empty($this->id)) { // being created, check for existing username
$vCond = array('User.username'=>$this->data['User']['username']);
if ($this->find('count',array('conditions'=>$vCond))>0) { // taken
$this->invalidate('username_taken_error');
return false;
} // fi
} // fi
return true;
}
}
?>

User Controller

<?php
/**
* @author Son Nguyen
* @since 12/16/2008
* @package LearningCake
* @subpackage User
*/
class UsersController extends AppController {
var $helpers = array('Html','Form');
var $components = array('Auth');

/** comment */
function beforeFilter() {
$this->Auth->allow('register');
}

/** comment */
function login() {}

/** comment */
function logout() {
$this->redirect($this->Auth->logout());
}

function register() {
$this->Auth->logout();
if (!empty($this->data)) {
$this->User->create();
if ($this->User->save($this->data)) {
$this->Auth->login($this->data); // autologin
$this->redirect(array('action'=>'index'));
} // fi
} // fi
}
}
?>

View - register.ctp

<?php
echo $form->create('User',array('action'=>'register'));
echo $form->input('username',array('after'=>$form->error('username_taken_error','Sorry! This username has been taken. Please choose another one')));
echo $form->input('password',array('value'=>''));
echo $form->input('password_confirm', array('value'=>'','type'=>'password','error'=>'Please enter your password again'));
echo $form->end('Register');
?>