quickstart – vkládání komentáře

rubla
Člen | 2
+
0
-

Ahoj, začínám s nette a jedu podle quickstartu, ale asi jsem někde udělal chybu. Dělám konkrétně komentáře – zobrazení mi funguje, ale nefunguje mi vložení. Jakmile dám vložit, objeví se mi chybová hláška. Nedojde k zápisu do db…
Mám červeně označený řádek 53…

TypeError

Argument 2 předaný App \ Presenters \ PostPresenter :: commentFormSucceeded () musí být instancí App \ Presenters \
stdClass, instance Nette \ Utils \ ArrayHash given  search►

Zdrojový soubor
Soubor: ... \ htdocs \ nette-blog \ app \ presenters \ PostPresenter.php : 53

43:            ->setRequired();
44:
45:        $form->addSubmit('send', 'Publikovat komentář');
46:
47:        $form->onSuccess[] = [$this, 'commentFormSucceeded'];
48:
49:        return $form;
50:    }
51:
52:
53:        public function commentFormSucceeded(Form $form, stdClass $values)
54:    {
55:        $postId = $this->getParameter('postId');
56:
57:        $this->database->table('comments')->insert([
Mistrfilda
Člen | 76
+
0
-

Ahoj,

je tam chyba u typehintu, před stdClass ti chybí lomítko nebo přidat use.

use stdClass;

nebo

public function commentFormSucceeded(Form $form, \stdClass $values)

Editoval Mistrfilda (29. 11. 2018 13:28)

Ondřej Kubíček
Člen | 494
+
+1
-

a hlavně si tam předáváš ArrayHash, takže bys spíš měl mít definici metody commentFormSucceeded takto:

use Nette\Utils\ArrayHash;
...
public function commentFormSucceeded(Form $form, ArrayHash $values)
rubla
Člen | 2
+
0
-

Děkuji, pomohlo lomítko a ArrayHash jsem doplnil také. Vše funguje :-)

nightfish
Člen | 471
+
+2
-

Ondřej Kubíček napsal(a):
a hlavně si tam předáváš ArrayHash, takže bys spíš měl mít definici metody commentFormSucceeded takto:

Není třeba, bude to fungovat i se \stdClass, neboť class ArrayHash extends \stdClass.

Ondřej Kubíček
Člen | 494
+
+2
-

Samozřejmě vím, ale o to vůbec nejde. Nechápu proč se zbytečně matou nováčci a není v dokumentaci rovnou ArrayHash, který tam vlastně reálně dostáváš. Podle mě zbytečná komplikace.