Friday, May 23, 2014

load 2 models in controller

Hi,

In my view I want to display data from 2 tables (maybe not related).
I read i do the following to load 2 model in a controller and simply access the other model in the view.

I get an error in the view file so this method of loading 2 models in a contrller doesnt work?

Undefined index: Teacher


class TutorsessionsController extends AppController
{
   
//do I need to add anything here like public $uses?

public  function index()
{
   $this->set('tutor',$this->Tutorsession->find('all'));
 
  
   $this->loadModel('Teacher');
$this->set('teacher', $this->Teacher->find('all'));
}

in View

.....
  foreach ($teacher as $item):
        echo '<tr><td>'. $item['Teacher']['id']. '</td>';

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: