title: cakephp - view with data from multiple tables
body: <p>i am working on a Cakephp 2.x. I have two tables in my app: 'Images' and 'Audios'... i have a view in which i want to show the images and videos both sorted by date ... dont know how to do this ... because the main problem is in Cakephp if you want to show image we do this </p>
  
  <pre><code>echo $data['Image']['filename'];
  </code></pre>
  
  <p>and for audio i do this </p>
  
  <pre><code>echo $data['Audio']['filename'];
  </code></pre>
  
  <p>we have to specify the modal name specifically.. but now i dont want to do this.. i want to show in random sorted by date.. for example if today someone uploaded an image and yesterday an audio was uploaded ... so the data has to look like this on the view page</p>
  
  <pre><code>audio.mp3 ,image.jpg .....so on
  </code></pre>
  
  <p>like this ..</p>
  
  <p>i dont want to write like this </p>
  
  <pre><code>foreach($datas as $data){
      echo $data['Image']['filename'];
      echo $data['Audio']['filename'];
  }
  </code></pre>
  
  <p>here i am explicitly telling that image comes first and then the audio which i dont want ... </p>
  
  <p><strong>my Images Model</strong> </p>
  
  <pre><code>function getImagesAndAudio($userid){
      $this-&gt;bindModel(array(
          'belongsTo' =&gt; array(
              'Audio' =&gt; array(
                  'className' =&gt; 'Audio',
                  'foreignKey' =&gt; false,
                  'conditions' =&gt; array(
                      'Image.user_id = Audio.user_id',
                  ),
                  'type' =&gt; 'LEFT',
              )
          )
      ), false);
  
      return $this-&gt;find('all', array('conditions' =&gt; array('Image.User_id' =&gt; $userid),
          'contain' =&gt; array('Audio' ),
      ));
  }
  </code></pre>
  
  <p>passing data from controller like this </p>
  
  <pre><code>$data = $this-&gt;Image-&gt;getImagesAndAudio($userid);
  $this-&gt;set('datas', $data);
  </code></pre>