Undefined variable: news v Homepage\default.latte
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- Piticu
- Člen | 93
Muze mi prosim nekdo rict proc mi nemuze najit promennu $news? Vubec na to nemuzu prijit.
HomepagePresenter
class HomepagePresenter extends BasePresenter
{
/** @var Model\ContentManager @inject*/
public $contentManager;
public function defaultRender(){
$this->template->news = $this->contentManager->getNews($this->lang);
}
}
Homepage\default.latte
<div n:foreach="$news as $item" class="blog-post">
<h2 class="blog-post-title">{$item->title}</h2>
<p class="blog-post-meta">{$item->date|date:'F j, Y'}</p>
<p>{$item->text}</p>
</div><!-- /.blog-post -->
ContentManager
class ContentManager extends Nette\Object
{
/**
* @var Nette\Database\Context
*/
private $database;
/**
* @param Nette\Database\Context $database
*/
public function __construct(Nette\Database\Context $database){
$this->database = $database;
}
public function getNews($lang){
return $this->database->table('news')
->where('lang',$lang);
}
}