hey guys, i’ve run into this issue when creating new entries via ee(‘Model’)->make(‘ChannelEntry’). All other fields work fine, inc. grid, relationship etc… but for some reason categories are always returning and error, see below:
Undefined index: categories[cat_group_id_1] ee/ExpressionEngine/Model/Content/ContentModel.php, line 143
Call to a member function setData() on null ee/ExpressionEngine/Model/Channel/ChannelEntry.php:773 ee/ExpressionEngine/Library/Data/Entity.php(410): ExpressionEngine\Model\Channel\ChannelEntry->set__categories(Array) …
the categories part of $entry_data that’s passed to the model.
‘categories’ => array (size=1) ‘cat_group_id_1’ => array (size=1) 0 => string ‘2’ (length=1)
… $newEntry = ee(‘Model’)->make(‘ChannelEntry’); $newEntry->set($entry_data); $validate = $newEntry->validate(); …
Validation passed.
EDIT: Category group and category definitely exists.
Any ideas?
Cheers, Mark
You should look at setting the relationship directly.
I think it would be something like:
$entry = ee(‘Model’)->make(‘ChannelEntry’);
$category = ee('Model')->get('Category')->filter('category_id', $categoryId)->all();
$entry->Categories = $category
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.