0

也许这是一个简单的问题,但我不知道如何处理它。我在PodcastsUsers及其在CakePHP 2.3.6. 用户可以“订阅”播客。

我想

  1. 获取当前登录用户的所有播客
  2. 使用 CakePHP-emailcomponent将文件(.opml,一种 XML 格式)发送到当前登录用户的电子邮件,其中包含特定格式的 podcasts 表的字段。

1. 获取所有播客:这就是我所拥有的。 debug($this->viewVars)告诉我数组是false.. 为什么?

模型/播客.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;
}

用户控制器.php

public function showMyPodcasts() {
   $userId = $this->Session->read('Auth.User.Id');
   $this->loadModel('Podcast');
   $podcasts = $this->Podcast->getPodcastsByUserId($userId);
   $this->set('podcasts', $podcasts);
}

2.发送文件

只是一个基本的想法或方法将非常有帮助!

4

1 回答 1

1

CakeEmail 在这里有很好的例子,解释......等等:http: //book.cakephp.org/2.0/en/core-utility-libraries/email.html

于 2013-06-22T06:49:07.710 回答