$postId = $this->getParameter(‚postId‘); vracia null
- chiquitin
- Člen | 9
<?php
namespace App\Presenters ;
use Nette;
use Nette\Application\UI\Form;
Class PostPresenter extends Nette\Application\UI\Presenter{
private $database;
public function __construct(Nette\Database\Context $database){
$this->database = $database;
}
public function renderShow (int $PostId):void
{
$post =$this->database->table('posts')->get($PostId);
if(!$post)
$this->error('stranka sa nenasla');
$this->template->post=$post;
$this->template->post = $post;
$this->template->comments = $post->related('comment')->order('created_at');
}
protected function createComponentCommentForm(): Form
{ $form = new Form;
$form -> addText('name','Meno')
-> setRequired();
$form -> addEmail('email','Email');
$form -> addTextArea('content','Komentar')
-> setRequired();
$form -> addSubmit ('send','Publikovat komentar');
$form->onSuccess[] = [$this,'commentFormSucceeded'];
return $form;
}
public function commentFormSucceeded(Form $form, \stdClass $values): void
{
$postId = $this->getParameter('postId');
$this->database->table('comments')->insert([
'post_id' => $postId,
'name' => $values->name,
'email' => $values->email,
'content' => $values->content
]);
$this->flashMessage('Děkuji za komentář', 'success');
$this->redirect('this');
}
}
zdravim som v nette novy a ma problem ze mi $postId = $this->getParameter(‚postId‘); vracia null. tym padom sa mi pri inserte nazapisuju id postov a komentare sa nepriraduju k postom. Dakujem za rady
Editoval chiquitin (18. 4. 2019 0:12)
- Mistrfilda
- Člen | 76
Ahoj,
myslím že tam máš překlep ve velikosti písmen.
U render metody máš velké písmeno na začatká, přepiš to na
<?php
public function renderShow (int $postId):void
?>
Doporučuju držet malá písmena na začátku.