ユーザーがコースに登録できるかどうかを確認しようとしています。私は2つの質問を持っています:CakePHP:ユーザーがAコースに登録できるようにする
- 私はこれについて正しい方向に行きますか?
- student :: isSignedUpForCourse()関数が適切なコースを返さない(実際には2つのコースを返す)。コースモデルで使用されているコース(Course :: CanSignupForCourse)を送信するにはどうすればよいですか?
ありがとう!
// Course Model
public function isComplete() {
$course = $this->read(null);
if($course['Course']['completed'] != 0) {
return true;
}
return false;
}
public function canSignupForCourse($studentId) {
$this->Student->id = $studentId;
if (!$this->Student->exists()) {
throw new NotFoundException(__('Invalid student'));
}
$this->Student->isSignedUpForCourse();
//this will ultimately be:
//if(! $this->Student->isSignedUpForCourse && $this->isApproved()) {
// return
}
}
// Course Controller:
public function signup($id = null) {
$this->Course->id = $id;
if (!$this->Course->exists()) {
throw new NotFoundException(__('Invalid course'));
}
if($this->Course->canSignupForCourse($this->Auth->user('id'))) {
// can signup
}
}
// Student Model
public function isSignedUpForCourse() {
print_r($this->read());
}
これはコースモデルです。 – execv
上記の私の更新を参照してください。 –