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 Answer 1

1

Have a look at Stephen Lewis' archived blog article about validation. Even better, buy the book.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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