This is making me feel dumb
I have a controller for MemberBadges, a MemberBadge can belong to a Member, and can also belong to Form28 (named for old paper based forms used to group MemberBadges)
I have an action in MemberBadgesController âaddbymemberâ, the member_id is based as an argument and this works fine.
However an action in the same controller an action âaddbyform28â with the form28_id as an argument gives an error âCall to a member function newEmptyEntity() on nullâ
Notice (1024) : Undefined property: MemberBadgesController::$MemberBadges in /Applications/MAMP/htdocs/aal-admin2/src/Controller/MemberbadgesController.php on line 181 [in /Applications/MAMP/htdocs/aal-admin2/vendor/cakephp/cakephp/src/Controller/Controller.php, line 337]
Code
Cake\Controller\Controller::__get() /Applications/MAMP/htdocs/aal-admin2/vendor/cakephp/cakephp/src/Controller/Controller.php, line 337
App\Controller\MemberBadgesController::addbyform28() /Applications/MAMP/htdocs/aal-admin2/src/Controller/MemberbadgesController.php, line 181
The offending bit of code is
public function addbyform28($form28Id = null)
{
$form28sTable = $this->getTableLocator()->get('Form28s');
$unitsTable = $this->getTableLocator()->get('Units');
$form28 = $form28sTable->get($form28Id, [
'contain' => [
'MemberBadges',
'Units',
'Form28Statuses',
],
]);
$unit = $unitsTable->get($form28->unit_id);
$this->Authorization->authorize($unit, 'basicEditor');
$memberBadge = $this->MemberBadges->newEmptyEntity(); <- THIS LINE
Sure Iâm doing something dumb hereâŚ