【发布时间】:2023-03-26 11:11:02
【问题描述】:
我在 appController 中创建了一个函数来发送电子邮件:
protected function sendEmail($studentId = null, $courseId = null, $action = null) {
$course = $this->Course->find('first', array('conditions' => array('Course.id' => $courseId)));
if(! $course) {
throw new NotFoundException(__('Invalid course'));
}
}
我想验证课程和学生,但根据我从哪个控制器调用它,我必须修改我的 $this->xxx->find 语句。我想出的唯一其他解决方案是验证/发送 $course/$student 数据头,但我仍然想运行手动 SQL 查询来保存电子邮件日志(我会遇到相同的情况问题)。有什么帮助吗?
【问题讨论】:
-
如果我理解正确的话;只需在您的
AppController中加载Course模型。每个控制器都可以访问它。这样,任何控制器都可以调用该函数。$this->loadModel('Course');在sendEmail函数中应该这样做。
标签: cakephp