Title says all. I’ll have navigation that looks like this and it’s dynamically created from database.
<ul>
<li><a href='controller/view/1'>1</li>
<li><a href='controller/view/2'>2</li>
<li><a href='controller/view/3'>3</li>
</ul>
It should be same on every page (by page, I mean on every controller), except for the active one. It’s my first time in cakephp.
This is my elements file:
<ul id="left-navigation">
<?php
App::import('Model','Godina');
$navigacija = $this->Godina->find('all');
foreach($navigacija as $nav){
echo '<li>' . $this->html->link($nav['Godina'] ['godina'],array('controller'=>'godina','action'=>'program',$nav['Godina']['godina'])
) . '</li>';
}
?>
And this is the error that I am getting.
Fatal error: Call to a member function find() on a non-object in /Applications/MAMP/htdocs/cakephp/app/View/Elements/godineNavigacija.ctp on line 4
And since my knowledge of cakephp core is quite low, it just doesn’t work.
Thanks.
App::importjust loads the file, like PHP’sinclude, it does not instantiate an object. So$this->Godinadoes not exist. You can do this:For proper MVC separation, you should not use models in the view though. You can fetch and
setthe data inAppController::beforeFilter, so it does it on every page, then output in the view. Alternatively, look intorequestAction.