Where to put my custom validators?

4 messages Options
Embed this post
Permalink
dmitrybelyakov

Where to put my custom validators?

Reply Threaded More More options
Print post
Permalink
Hello everybody,

I just wonder if there's a default or recommended location for custom validator classes that go along with my module's forms. I am having trouble getting it to work and actually autoload. Any help is greatly appreciated.

Dmitry.
Mike Willbanks-3

Re: Where to put my custom validators?

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

Typically what I have done with validators in the past is create another directory in the library folder (especially if I know I am going to use it again).

What I end up having is something like: library/MyCodeBase/Validators/* and add them into the autoloader.  You could essentially do this from within the module directory or even create a new directory under your file system.


You might also want to peak a bit more into the documentation on writing the custom validators: http://framework.zend.com/manual/en/zend.validate.writing_validators.html


Regards,


Mike

 

----- Original Message -----

From: dmitrybelyakov

Sent: 06/30/09 02:03 pm

To: [hidden email]

Subject: [fw-mvc] Where to put my custom validators?

 


Hello everybody,

I just wonder if there's a default or recommended location for custom
validator classes that go along with my module's forms. I am having trouble
getting it to work and actually autoload. Any help is greatly appreciated.

Dmitry.
--
View this message in context: http://www.nabble.com/Where-to-put-my-custom-validators--tp24277729p24277729.html
Sent from the Zend MVC mailing list archive at Nabble.com.

 


dmitrybelyakov

Re: Where to put my custom validators?

Reply Threaded More More options
Print post
Permalink

Mike Willbanks-3 wrote:
Typically what I have done with validators in the past is create another directory in the library folder (especially if I know I am going to use it again).

What I end up having is something like: library/MyCodeBase/Validators/* and add them into the autoloader.  You could essentially do this from within the module directory or even create a new directory under your file system.

You might also want to peak a bit more into the documentation on writing the custom validators: http://framework.zend.com/manual/en/zend.validate.writing_validators.html

Regards,
Mike

Hi Mike,

Thanks for your reply. The reference guide was quite clear on how to write validators but a bit unclear on where to put them. My concern was how to do it properly in the MVC layout to autoload per-module, but now i see that default module autoloader implementation does not search for validators as it does for forms, models or apis (what's that by the way?) so you need to setup the autoloading for validators yourself.

Just was unsure if i did it the right way. Now it's completely clear.

Good luck.
Dmitry.
Nicolas GREVET

Re: Where to put my custom validators?

Reply Threaded More More options
Print post
Permalink
You can also add this to your form element or a parent class:
    $this->addElementPrefixPath('MyPrefix_Validate_',
'MyPrefix/Validate/', 'validate');
If you don't want to add an autoloader for it.

Regards,
-- Nicolas



dmitrybelyakov a écrit :

>
> Mike Willbanks-3 wrote:
>  
>> Typically what I have done with validators in the past is create another
>> directory in the library folder (especially if I know I am going to use it
>> again).
>>
>> What I end up having is something like: library/MyCodeBase/Validators/*
>> and add them into the autoloader.  You could essentially do this from
>> within the module directory or even create a new directory under your file
>> system.
>>
>> You might also want to peak a bit more into the documentation on writing
>> the custom validators:
>> http://framework.zend.com/manual/en/zend.validate.writing_validators.html
>>
>> Regards,
>> Mike
>>
>>    
>
>
> Hi Mike,
>
> Thanks for your reply. The reference guide was quite clear on how to write
> validators but a bit unclear on where to put them. My concern was how to do
> it properly in the MVC layout to autoload per-module, but now i see that
> default module autoloader implementation does not search for validators as
> it does for forms, models or apis (what's that by the way?) so you need to
> setup the autoloading for validators yourself.
>
> Just was unsure if i did it the right way. Now it's completely clear.
>
> Good luck.
> Dmitry.
>
>