Anatoliy
Well-known member
When I hit the Save button while adding a new note, I'm getting the error
I watched videos several times but failed to figure out what's wrong. Here's my controller.
Please help.
Code:
TypeError: Demo\Pad\Pub\Controller\Note::actionSave(): Argument #1 ($params) must be of type Demo\Pad\Pub\Controller\ParameterBag, XF\Mvc\ParameterBag given, called in /Applications/XAMPP/xamppfiles/htdocs/src/XF/Mvc/Dispatcher.php on line 362 in src/addons/Demo/Pad/Pub/Controller/Note.php at line 55
Demo\Pad\Pub\Controller\Note->actionSave() in src/XF/Mvc/Dispatcher.php at line 362
XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 264
XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 121
XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 63
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2813
XF\App->run() in src/XF.php at line 802
XF::runApp() in index.php at line 23
I watched videos several times but failed to figure out what's wrong. Here's my controller.
PHP:
<?php
namespace Demo\Pad\Pub\Controller;
use XF\Pub\Controller\AbstractController;
class Note extends AbstractController
{
public function actionIndex()
{
return $this->view('Demo\Pad:Note\Index', 'demo_pad_index');
}
public function actionTest()
{
// $userFinder = $this->finder('XF/User')
// ->where('user_id', '<', 4);
// $total = $userFinder->total();
// $users = $userFinder->fetch();
// $note = $this->em()->create('Demo\Pad:Note');
// $note->title = 'First note title';
// $note->content = 'First nnote content...';
// $note->save();
$viewParams = [
];
return $this->view('Demo\Pad:Note\Test', 'demo_pad_test', $viewParams);
}
public function actionAdd()
{
$note = $this->em()->create('Demo\Pad:Note');
return $this->noteAddEdit($note);
}
public function actionEdit(ParameterBag $params)
{
$note = $this->assertNotedExist($params->note_id);
return $this->noteAddEdit($note);
}
protected function noteAddEdit(\Demo\Pad\Entity\Note $note)
{
$viewParams = [
'note' => $note
];
return $this->view('Demo\Pad:Note\Edit', 'demo_pad_edit', $viewParams);
}
public function actionSave(ParameterBag $params)
{
if($params->note_id)
{
$note = $this->assertNotedExist($params->note_id);
}
else
{
$note = $this->em()->create('Demo\Pad:Note');
}
$this->noteSaveProcess($note)->run();
return $this->redirect($this->buildLink('notes'));
}
protected function noteSaveProcess(\Demo\Pad\Entity\Note $note)
{
$input = $this->filter([
'title' => 'str',
'content' => 'str'
]);
$form = $this->formAction();
$form->basicEntitySave($note, $input);
return $form;
}
protected function assertNoteExist($id, $with = null, $phraseKey = null)
{
return $this->assertRecordExist('Demo\Pad:Note', $id, $with, $phraseKey);
}
}
Please help.