2012-03-08 3 views
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クエリを実行したいと思います(同じ問題)。どんな助け?

+1

私は正しく理解していれば、あなたの 'AppController'に' Course'モデルをロードするだけです。すべてのコントローラーがアクセスできます。そうすれば、どんなコントローラーもその機能を呼び出すことができます。 'sendEmail'関数の' $ this-> loadModel( 'Course');がそれを行うべきです。 – Ross

答えて

0

私は非常に良いあなたの問題を理解しますが、していない:それは大丈夫だ、あるいはそうでない場合

を、TELは私は...私のコードに基づいて、新しいideeaが付属しています。私は今あなたのデータベース構造はありませんが、私はそれが結合クエリを動作すると思う...

$course = $this->Course 
$student = $this->Student 
    if(!empty($student) && !empty($course)): $status = 3 endif; 
    if(empty($student)): $status1 = 1 else: $status = 0 endif; 
    if(empty($course)): $status2 = 2 else: $status = 0 endif; 
    if(empty($status)): 
     $array=array($status1,status2); 
    else: 
     $array=array($status); 
    endif; 
     foreach($array as $key => $value) 
     if($value == 1):throw new NotFoundException(__('Invalid course')); 
     if($value == 2):throw new NotFoundException(__('Invalid student')); 
     if($value == 0):throw new NotFoundException(__('Invalid course and student')); 
     if($value == 3):throw new NotFoundException(__('Valide course and student')); 
     endforeach; 
関連する問題