Cannot read an undeclared property PagePresenter::$model

Notice: This thread is very old.
ivanscm
Member | 16
+
0
-

What am I doing wrong? Follow the manual does not work.

class PagePresenter extends BasePresenter
{

	public function renderShow($name)
	{
		$this->template->page_content = $this->model->getPage($name);
	}

}

Not ORM?

Jan Tvrdík
Nette guru | 2595
+
0
-

ivanscm: How do you expect the code should work? Nette does not define model property so if you want to use it you must specify it yourself. For example you may add the following code to BasePresenter

class BasePresenter extends ...
{
	public $model;
	protected function startup()
	{
		parent::startup();
		$this->model = new YourModel(); // you must create class YourModel first
	}
}

Another solution could be to create getter.

class BasePresenter extends ...
{
	private $model;
	public function getModel()
	{
		if ($this->model === NULL) $this->model = new YourModel();
		return $this->model;
	}
}
ivanscm
Member | 16
+
0
-

Thank you so much!