Anatoliy
Well-known member
notes/edit gives me "The requested page could not be found." error. But actionEdit is exist in a controller.
notes/add works just fine - displays a form, then saves the data, and redirects to notes listing.
where did I make an error?

notes/add works just fine - displays a form, then saves the data, and redirects to notes listing.
where did I make an error?
PHP:
<?php
namespace Demo\Pad\Pub\Controller;
use XF\Mvc\ParameterBag;
use XF\Pub\Controller\AbstractController;
class Note extends AbstractController{
protected function preDispatchController($action, ParameterBag $params)
{
$this->assertRegistrationRequired();
}
public function actionIndex(ParameterBag $params){
$noteFinder = $this->finder('Demo\Pad:Note')
->where('user_id', \XF::visitor()->user_id)
->order('post_date', 'desc');
$page = $params->page;
$perPage = 20;
$noteFinder->limitByPage($page, $perPage);
$viewParams = [
'notes' => $noteFinder->fetch(),
'page' => $page,
'perPage' => $perPage,
'total' => $noteFinder->total()
];
return $this->view('Demo\Pad:Note\Index', 'demo_pad_index', $viewParams);
}
public function actionAdd()
{
$note = $this->em()->create('Demo\Pad:Note');
return $this->actionAddEdit($note);
}
public function actionEdit(ParameterBag $params)
{
$note = $this->assertNoteExists($params->note_id);
return $this->actionAddEdit($note);
}
protected function actionAddEdit(\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->assertNoteExists($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;
}
/**
* @param $id
* @param null $with
* @param null $phraseKey
*
* return \Demo\Pad\Entity\Note
* return \XF\Mvc\Reply\Exception
*/
protected function assertNoteExists($id, $with = null, $phraseKey = null)
{
return $this->assertRecordExists('Demo\Pad:Note', $id, $with, $phraseKey);
}
}