Friday, May 23, 2014

RE: load 2 models in controller

Why not use the standard relations?

 

One would think the Teacher hasManyTutorSession <-> TutorSession BelongsTo Teacher.

So when you get Teacher data you would get the TutorSession or vice versa.

You get the TutorSession and that would have the Teacher data.

 

 

 

From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of Andrew Barry
Sent: Saturday, May 24, 2014 3:04 AM
To: cake-php@googlegroups.com
Subject: 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: