Hi :)
I'm really new with phalconPHP, you made a really great job, but i get a tiny question, Phalcon is it really DRY ?
I'm writing an web application (Snippet share system for phalcon community) and i'm already tired ...
I made a controller with a simple method :
<?php
class SnippetController extends ControllerBase
{
public function addAction()
{
if ($this->request->isPost())
{
// Get post values
$language = $this->request->getPost('language');
$description = $this->request->getPost('description');
$code = $this->request->getPost('code');
$snippet = new Snippets();
$snippet->description = $description;
$saved = $snippet->save();
if ( ! $saved)
{
$errors = '';
foreach ($snippet->getMessages() as $message) {
$errors .= $message->getMessage() . '<br/>';
}
$this->flashSession->error($errors);
}
}
// Set languages code into the view
$this->view->setVar('languages', $this->config->languages->toArray());
}
}
And a simple model :
<?php
use Phalcon\Mvc\Model\Validator\PresenceOf;
class Snippets extends \Phalcon\Mvc\Model
{
/**
*
* @var integer
*/
public $id;
/**
*
* @var string
*/
public $description;
/**
* Independent Column Mapping.
*/
public function columnMap()
{
return array(
'id' => 'id',
'description' => 'description'
);
}
public function validation()
{
$this->validate(new PresenceOf(
array(
'field' => 'description',
'message' => 'Le champ description est requis'
)
));
$this->validate(new PresenceOf(
array(
'field' => 'code',
'message' => 'Le champ code est requis'
)
));
if ($this->validationHasFailed() === TRUE) {
return FALSE;
}
}
}
Just to check 2 tiny required fields, i wrote more than 16 lines (A system to get error messages, and $this->validate() system)
In my previous framework, i made this for example :
// Add rules
$this->validation->rules('field_to_check', 'message', 'required|max_length[2]|equal[another_field]');
// Get errors
$this->validation->errors(); // Ready to print in the view
Don't forget i'm really new with Phalcon, maybe i made wrong/worst code, so what's the DRY way to check forms ?
Thx ;)