0
のAppControllerのモデル:CakePHPの:私はsendemailsに私の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'モデルをロードするだけです。すべてのコントローラーがアクセスできます。そうすれば、どんなコントローラーもその機能を呼び出すことができます。 'sendEmail'関数の' $ this-> loadModel( 'Course');がそれを行うべきです。 – Ross