2008年11月28日星期五

Re: [fw-mvc] Zend_Form and Doctrine Integration

I've done something similar in my projects using Zend_Db_Table though (and a lot of override options)

I really like django's model based forms and wish there was something internal in Zend framework like that.


On Fri, Nov 28, 2008 at 6:36 AM, Емил Иванов / Emil Ivanov <emil.vladev@gmail.com> wrote:
Hi all,

lately I've been working on integrating Zend_Form and Doctrine models.

What I tried to accomplish is something similar to django's
model-based forms. You have a model, that knows a hell lot of
information about itself, and you can create a form for it in one
line.
I uploaded what I have done here:
http://github.com/Vladev/zend-form-doctrine/tree/master

Check it out - there are tests that show the usage.

It's actually quite simple:

$form = new ZendX_Doctrine_Form(new Book()); // Book is an instance of
Doctrine_Record

And you are done.
It will create fields for all of the columns in the model (except for
pk and foreign keys). This can be overriden.

Right now it supports strings, integers and booleans columns, as well
as relations.
For relations it will generate the appropriate select (multi or not).
Again, can be overriden.

Validation is done by actually validating the model itself and
checking which columns did not validated.
Messages are attached to the form to indicate that.
No validators are added to the form itself.

Extending is done via subclassing the form and overriding some of the
methods. I've tried to keep them short and concise.

I'm considering including this is ZF, but don't know how exactly and
whether someone would like it.

So, have a look and share your thoughts. :)

P.S. Tests might not run out of the box as I extracted the code from
another app where we're using a custom runner. I've also renamed the
classes to ZendX_ instead of OutApp_.

Regards,
Emil Ivanov
--
My place to share my ideas:
http://vladev.blogspot.com
http://carutoo.com


没有评论: