2

I'm trying to get a better understanding of how to define new models in plugins, but the documentation at http://buildwithcraft.com/docs/plugins/models doesn't get me very far.

For example, there is:

protected function defineAttributes()
{
    return array(
        'name' => AttributeType::String,
        'type' => array(AttributeType::Enum, 'values' => "alcohol,mixer,other"),
    );
}`

I've seen other plugins define attributes with an array element of 'required' => true, but the only example I see here is 'values'. Is there somewhere I can see a list of the available options when defining attributes? Or is it a better practice to define the attributes simply and then define validation rules in the rules() method?

I know the docs say to check out the CModel documentation, but it doesn't even have defineAttributes. Does Craft itself have more in depth documentation on this topic?

1

Have a look at Stephen Lewis' blog article about validation:
https://experiencehq.net/blog/the-definitive-guide-to-validation-in-craft-part-1-foundations

or even better, buy the book:
The Definitive Guide to Craft Validation for Plugin Developers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.