0

In a plugin I am returning entries from a section. Can I combine a returned entry from that section with data from a custom table into one model for output?

1 Answer 1

1

Just have your plugin supply a custom MyPluginEntryModel that extends Craft's EntryModel and merges in any custom attribute definitions from your custom table.

class MyPluginEntryModel extends EntryModel
{
   ....

    protected function defineAttributes()
    {
        return array_merge(parent::defineAttributes(), array(
            'customAttribute1' => AttributeType::Number,
            'customAttribute2' => AttributeType::String,
        ));
    }

   ....
}
8
  • Then how do I populate the model with both the entry and custom data?
    – a-am
    Jan 9, 2015 at 4:03
  • I think this should work? $outputModel = MyPluginEntryModel::populateModel($entry,$tablerecord);
    – a-am
    Jan 9, 2015 at 4:13
  • That doesn't seem to work. My goal would be to return a model instead of an array of models.
    – a-am
    Jan 9, 2015 at 4:54
  • You'll need to post the code you're using in the original question. Can't tell what's going on otherwise.
    – Brad Bell
    Jan 9, 2015 at 5:42
  • I got that to work just now. How do I return a model to the front end instead of an array of models?
    – a-am
    Jan 9, 2015 at 5:50

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.