Quickstart – problem s komentármi
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- errorqo
- Člen | 4
čaute, chcem sa spytat na tuto chybu "":http://prntscr.com/8xnthd pri quick starte s komentarmi, ako
ju vyriesit a vysvetlit preco sa ta chyba naskytla… za odpovede vopred
dakujem
toto je moj presenter
<?php
namespace App\Presenters;
use Nette,
Nette\Application\UI\Form;
class PostPresenter extends BasePresenter
{
/** @var Nette\Database\Context */
private $database;
public function __construct(Nette\Database\Context $database)
{
$this->database = $database;
}
public function renderShow($postId)
{
$this->template->post = $this->database->table('blog_posts')->get($postId);
$this->template->post = $post;
$this->template->comments = $post->related('comment')->order('date_comment');
}
public function createComponentCommentForm() {
$form = new Form;
$form->addText('name','Meno:')
->setRequired();
$form->addTextArea('content', 'Komentár:')
->setRequired();
$form->addSubmit('send', 'Publikuj');
$form->onSuccess[] = array($this, 'commentFormSucceeded');
return $form;
}
public function commentFormSucceeded($form, $values) {
$postId = $this->getParameter('postId');
$this->database->table('comments')->insert(array(
'post_id' => $postId,
'name' => $values->name,
'text' => $values->text,
));
$this->flashMessage('Ďakujem za komentár', 'success');
$this->redirect('this');
}
}
a tu je šablona
{foreach $comments as $comment}
<p><b>{$comment->name}</b> napisal:</p>
<div>{$comment->content}</div>
{/foreach}
Editoval errorqo (1. 11. 2015 3:47)
- David Matějka
- Moderator | 6445
Ahoj, asi si prehlidnul tuhle cast v quickstartu: https://doc.nette.org/…/single-post#…