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
echo $data['Image']['filename'];
and for audio i do this
echo $data['Audio']['filename'];
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
audio.mp3 ,image.jpg .....so on
like this ..
i dont want to write like this
foreach($datas as $data){
echo $data['Image']['filename'];
echo $data['Audio']['filename'];
}
here i am explicitly telling that image comes first and then the audio which i dont want ...
my Images Model
function getImagesAndAudio($userid){
$this->bindModel(array(
'belongsTo' => array(
'Audio' => array(
'className' => 'Audio',
'foreignKey' => false,
'conditions' => array(
'Image.user_id = Audio.user_id',
),
'type' => 'LEFT',
)
)
), false);
return $this->find('all', array('conditions' => array('Image.User_id' => $userid),
'contain' => array('Audio' ),
));
}
passing data from controller like this
$data = $this->Image->getImagesAndAudio($userid);
$this->set('datas', $data);