也许这是一个简单的问题,但我不知道如何处理它。我在Podcasts
和Users
及其在CakePHP 2.3.6
. 用户可以“订阅”播客。
我想
- 获取当前登录用户的所有播客
- 使用 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.发送文件
只是一个基本的想法或方法将非常有帮助!