Hi Dylan,

On Thu, Feb 28, 2008 at 7:40 AM, Dylan Arnold <[EMAIL PROTECTED]>
wrote:

> I was mostly wanting to use the fully qualified class name to avoid any
> weird naming conflicts. Ie i wanted my own My_Validate_Regex but was worried
> about the implications of ->addValidator('Regex', ...) when there is a
> Zend_Validate_Regex as well. It seems My_Validate_Regex takes precedence
> anyway.


If that's what you want, then you can directly instantiate My_Validate_Regex
and pass its instance to addValidator().
But anyway, IMHO, it's better to pass 'Regex' and let the plugin loader
figure it out as this way when you need to override the Regex validator, you
just configure the validators path prefix and everything works.

Best,
- Amr


>
>
> The documentation here was confusing me.
>
>
> http://framework.zend.com/manual/en/zend.form.elements.html#zend.form.elements.validators
>
> Cheers
>
>
> On Thu, Feb 28, 2008 at 5:38 PM, Matthew Weier O'Phinney <[EMAIL PROTECTED]>
> wrote:
>
> > -- Dylan Arnold <[EMAIL PROTECTED]> wrote
> > (on Thursday, 28 February 2008, 05:19 PM +1300):
> > > Can somebody please give me an example of using a custom validator
> > with
> > > Zend_Form?
> > >
> > > For the basic case using Zend_Validate_*:
> > > $element = new Zend_Form_Element_Text('test');
> > > $element->addValidator('Regex', ....);
> > > //works fine.
> > >
> > > However:
> > > $element->addValidator('Zend_Validate_Regex', ....);
> > > //doesn't work. I get an exception Plugin by name Zend_Validate_Regex
> > was not
> > > found in the registry. What am I doing wrong?
> >
> > By default, the plugin loader looks for a class that has one of the
> > registered prefixes. So, if you pass 'Regex' as the name, and
> > 'Zend_Validate' is a registerd prefix, it finds it. However,
> > there is no match to a fragment 'Zend_Validate_Regex' with an
> > *additional* 'Zend_Validate' prefix.
> >
> > So, either use the short name ('Regex', in your example), or instantiate
> > the validator:
> >
> >    $element->addValidator(new Zend_Validate_Regex($pattern));
> >
> > > Now lets say I created a custom validator My_Validate_Test:
> > > $element->addPrefixPath('My_Validate', 'My/Validate/',
> > > Zend_Form_Element::VALIDATE);
> > > $element->addValidator('Test', ....);
> > > //This works
> > >
> > > However:
> > > $element->addValidator('My_Validate_Test', ...);
> > > //Doesn't work. (Exception Plugin by name My_Validate_Test was not
> > found in the
> > > registry.
> > >
> > > Where am I going wrong?
> >
> > Same problem as above. You now have the prefixes "Zend_Validate" and
> > "My_Validate" on the stack, and it's prepending whatever you pass with
> > those prefixes when doing the lookup.
> >
> > > Also. Does $form->addElementPrefixPath('My_Validate', 'My/Validate/',
> > > Zend_Form_Element::VALIDATE); Add the path to all elements. I can only
> > get the
> > > path to work by setting it for each individual element.
> >
> > Should work on all elements... but only if they are created through your
> > form object (i.e., via createElement() or addElement()). If you're
> > instantiating your elements directly, you'd need to add the prefix path
> > to all elements individually, as they would have no form awareness until
> > added to the form.
> >
> > --
> > Matthew Weier O'Phinney
> > PHP Developer            | [EMAIL PROTECTED]
> > Zend - The PHP Company   | http://www.zend.com/
> >
>
>

Reply via email to