\Phalcon\Tag and Models should cooperate

22 views
Skip to first unread message

Wojtek Gancarczyk

unread,
Nov 5, 2012, 4:44:46 PM11/5/12
to phalcon-...@googlegroups.com
Hi,

Take a look at this example:


Basically what I'm trying to do, is to render form elements with corresponding error messages. For now it works perfectly. I just set \Custom\Tag::setErrors($model->getMessages()) in my controller and I'm automatically generating the markup for text and password form elements. If a field did not pass the validation, it will automatically get an error CSS class.

I was trying to take this example a step further and instead of just setting the error messages I was trying to set a model to be able to mark fields required or even more move the whole form generation to \Custom\Tag without the need for setting labels etc. I cannot find a way to check for example that a certain field/column is required. Can I get to this information through model somehow? It would be also cool if I could check if certain field did not pass validation (instead of looping through messages). I also wanted to provide a way to define custom templates for fields (for now I'm just using hardcoded bootstrap markup).

The bottom line is, I think it would be a nice addition to Phalcon, if \Phalcon\Tag would accept Model (\Phalcon\Tag::setModel) and maybe some arbitrary templates (volt?) for generating fields and corresponding error messages/required fields. In my case it would be just enough, if \Phalcon\Mvc\Model would provide something like that:

$model->isRequired($field) // returns boolean
$model->hasMessage($field) // returns boolean
$model->getMessage($field) // returns \Phalcon\Mvc\Model\Message|null

Best
Wojtek
Reply all
Reply to author
Forward
0 new messages