CakePHP 3.5 saving into another table


#1

I’m very new in cakephp 3.5 and I got problem with saving the data into different table. I have Question table and want to save the data into QuestionQuizzes table by using the checkbox function. When i try to submit the form, it got error saying 'The question could not be save".

QuestionController:

public function existingQuestion()

{

$this->loadModel('QuestionsQuizzes');
$questions = $this->paginate($this->Questions);
$questionsQuiz = $this->QuestionsQuizzes->newEntity();

if($this->request->is('post'))
{

    $question = $this->QuestionsQuizzes->patchEntity($questionsQuiz, 
    $this->request->getData());

    if ($this->Questions->save($questionsQuiz)) {
        $this->Flash->success(__('The question has been saved.'));

        return $this->redirect(['action' => 'existingQuestion']);
    }
    $this->Flash->error(__('The question could not be saved. Please, try again.'));

}

$this->set(compact('questions'));
$this->set('_serialize', ['questions']);

}

I just need the checked data can be saved into the database table.