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?
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,
));
}
....
}
-
-
I think this should work? $outputModel = MyPluginEntryModel::populateModel($entry,$tablerecord); – aran Jan 9 '15 at 4:13
-
That doesn't seem to work. My goal would be to return a model instead of an array of models. – aran Jan 9 '15 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 '15 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? – aran Jan 9 '15 at 5:50