0

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

  1. get all podcasts of the currently logged-in user
  2. 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!

dh762
  • 2,259
  • 4
  • 25
  • 44

1 Answers1

1

CakeEmail is very well documented here with examples, explanation...etc here: http://book.cakephp.org/2.0/en/core-utility-libraries/email.html

Dave
  • 28,833
  • 23
  • 113
  • 183