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
/** 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
/** 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
}
}
?>
Leave a Reply