Hello,
I have been following Kier tutorial on how to make a scratch pad thingy. I am very new to php coding.I have ran into an issue where I am getting a code error and don't know how to fix it.
Here is the Sever error log:
Here is the Note Controller:
From the error it looks like it doesn't like this line of code:
The code is correct from the video. Anyone have an idea as to why it doesn't work?
Thanks,
CipherX
I have been following Kier tutorial on how to make a scratch pad thingy. I am very new to php coding.I have ran into an issue where I am getting a code error and don't know how to fix it.
Here is the Sever error log:
Code:
LogicException: Unknown relation or alias User accessed on xFaddons_pad_note src\XF\Mvc\Entity\Finder.php:790
Generated by: Webmaster Feb 20, 2025 at 3:54 AM
Stack trace
#0 src\XF\Mvc\Entity\Finder.php(672): XF\Mvc\Entity\Finder->join('User', true, false, false)
#1 src\XF\Mvc\Entity\Manager.php(273): XF\Mvc\Entity\Finder->with(Array)
#2 src\XF\Mvc\Controller.php(1040): XF\Mvc\Entity\Manager->getFinder('xFaddons\\Pad:No...')
#3 src\addons\xFaddons\Pad\Pub\Controller\Note.php(13): XF\Mvc\Controller->finder('xFaddons\\Pad:No...')
#4 src\XF\Mvc\Dispatcher.php(362): xFaddons\Pad\Pub\Controller\Note->actionIndex(Object(XF\Mvc\ParameterBag))
#5 src\XF\Mvc\Dispatcher.php(264): XF\Mvc\Dispatcher->dispatchClass('xFaddons\\Pad:No...', 'Index', Object(XF\Mvc\RouteMatch), Object(xFaddons\Pad\Pub\Controller\Note), NULL)
#6 src\XF\Mvc\Dispatcher.php(121): XF\Mvc\Dispatcher->dispatchFromMatch(Object(XF\Mvc\RouteMatch), Object(xFaddons\Pad\Pub\Controller\Note), NULL)
#7 src\XF\Mvc\Dispatcher.php(63): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#8 src\XF\App.php(2826): XF\Mvc\Dispatcher->run()
#9 src\XF.php(806): XF\App->run()
#10 index.php(23): XF::runApp('XF\\Pub\\App')
#11 {main}
Request state
array(4) {
["url"] => string(17) "/index.php?notes/"
["referrer"] => string(36) "http://localhost/index.php?notes/add"
["_GET"] => array(1) {
["notes/"] => string(0) ""
}
["_POST"] => array(0) {
}
}
Here is the Note Controller:
Code:
<?php
namespace xFaddons\Pad\Pub\Controller;
use XF\Mvc\ParameterBag;
use XF\Pub\Controller\AbstractController;
class Note extends AbstractController
{
public function actionIndex()
{
$noteFinder = $this->finder('xFaddons\Pad:Note')
->where( 'user_id', \XF::visitor()->user_id)
->order('post_date', 'desc');
$viewParams = [
'notes' => $noteFinder->fetch()
];
return $this->view('xFaddons\Pad:Note\Index', 'xFaddons_pad_index', $viewParams);
}
public function actionTest()
{
$postFinder = $this->finder( 'XF:Post')
->with('User')
->with( 'User.Profile')
->with( 'Thread')
->where('user_id', '<>', 0);
/** @var \xFaddons\Pad\Entity\note $note */
$note = $this->em()->create( 'xFaddons\Pad:Note');
$note->title ='This is my first note title';
$note->content = 'This is my first note content';
$note->save();
$viewParams = [
'post' => $postFinder
];
return $this->view('xFaddons\Pad:Note\Test', 'xFaddons_pad_test', $viewParams);
}
public function actionAdd()
{
$note = $this->em()->create( 'xFaddons\Pad:Note');
return $this->noteAddEdit($note);
}
public function actionEdit(ParameterBag $params)
{
$note = $this->assertNoteExists($params->note_id);
return $this->noteAddEdit($note);
}
protected function noteAddEdit(\xFaddons\Pad\Entity\Note $note)
{
$viewParams = [
'note' => $note
];
return $this->view('xFaddons\Pad:Note\Edit', 'xFaddons_pad_edit', $viewParams);
}
public function actionSave(ParameterBag $params)
{
if ($params->note_id) {
$note = $this->assertNoteExists($params->note_id);
} else {
$note = $this->em()->create('xFaddons\Pad:Note');
}
$this->noteSaveProcess($note)->run();
return $this->redirect($this->buildLink('notes'));
}
protected function noteSaveProcess(\xFaddons\Pad\Entity\Note $note)
{
$input = $this->filter([
'title' => 'str',
'content' => 'str',
]);
$form = $this->formAction();
$form->basicEntitySave($note, $input);
return $form;
}
/**
* @param $id
* @param $with
* @param $phraseKey
* @return \xFaddons\Pad\Entity\Note
* @throws \XF\Mvc\Reply\Exception
*/
protected function assertNoteExists($id, $with = null, $phraseKey = null)
{
return $this->assertRecordExists('xFaddons\Pad:Note', $id, $with, $phraseKey);
}
}
Code:
$noteFinder = $this->finder('xFaddons\Pad:Note')
The code is correct from the video. Anyone have an idea as to why it doesn't work?
Thanks,
CipherX