Maybe it is a simple question, but I don't know how to approach it.
I have a HABTM-relationship between Podcasts
and Users
and its basic baked application in CakePHP 2.3.6
.
A User can "subscribe" to podcasts.
I'd like to
- get all podcasts of the currently logged-in user
- send a file (.opml, a XML-format) to the currently logged-in User's email using CakePHP-emailcomponent containing fields of the podcasts table in a specific formatting.
1. getting all podcasts: this is what I have.
debug($this->viewVars)
shows me that the array is false
.. Why?
Model/Podcast.php
public function getPodcastsByUserId($userId = null) {
if(empty($userId)) return false;
$podcasts = $this->find('all', array(
'joins' => array(
array('table' => 'podcasts_users',
'alias' => 'PodcastsUser',
'type' => 'INNER',
'conditions' => array(
'PodcastsUser.user_id' => $userId,
'PodcastsUser.podcast_id = Podcast.id'
)
)
),
'group' => 'Podcast.id'
));
return $podcasts;
}
UsersController.php
public function showMyPodcasts() {
$userId = $this->Session->read('Auth.User.Id');
$this->loadModel('Podcast');
$podcasts = $this->Podcast->getPodcastsByUserId($userId);
$this->set('podcasts', $podcasts);
}
2. sending a file
Just a basic idea or approach would be very helpful!