tonystamp wrote:
>
> I'm assuming a single service can be responsible for creating more than
> one type of form?
>
Sure, if that fits in with your workflow. In other words, if you are
creating a generic CRUD-like service, then any resource that fits that model
could have it's domain serviced via this generic service.
In other words:
$generic = GenericService::for('BlogPosts', $otherOptions);
$form = $generic->getFormFor(GenericService::FORM_CREATE);
NOTE: method 'for' is just an example of a factory and can be named just
about anything. "getFormFor" retrieves form objects for BlogPosts. The
constant designates the correct form object to retrieve. Obviously the
GenericService object knows where to locate forms pertaining to models.
tonystamp wrote:
>
> Is it the responsibility of the service layer to validate the form, and if
> so, how would it return form errors to the view?
>
With ZF1, Zend_Form instances contain the validation logic; however, there
is nothing stopping you from attaching Zend_Form instances to your models
and having a super-type which models extend from which contains the logic to
retrieve the form and validate. This way, you can do $myModel->isValid() in
a consistent way across models.
The exact order of things is up to you as there is no current emerging
convention. I've done it a few different ways and each basically gets me to
the same place. I'm still trying to figure out what I like best and which is
the most portable.
tonystamp wrote:
>
> how would it return form errors to the view?
>
I generally throw a specific exception which extends from SPL
DomainException, InvalidArgumentException, or UnexpectedValueException.
I augment this exception class with methods to:
a. Insert error messages
b. Retrieve error messages
This allows me to retrieve error messages in the controller and pass them to
the FlassMessenger helper and redirect (happens in the catch part). If there
are no errors, the create was a success and we can move on.
-----
--
Wil Moore III
Why is Bottom-posting better than Top-posting:
http://www.caliburn.nl/topposting.html
DO NOT TOP-POST and DO trim your replies:
http://linux.sgms-centre.com/misc/netiquette.php#toppost
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Service-Layer-and-form-validation-view-interaction-tp3336281p3337017.html
Sent from the Zend Framework mailing list archive at Nabble.com.