登记活动提交0而不是1和1而不是0,但仍然提供正确的Flash成功

When I get Successfully UNENLISTED(1)! the database saves the digit as 1 and when i get the response Successfully ENLISTED(1)! database saves the digit as 0. I'm very lost and confused from my problem. Is there something special I'm not understanding with CakePHP?

public function enlist($user_id_main, $user_id_from) {
    $this->render(false);
    $this->loadModel('Enlist');
    $enlist = $this->Enlist->getEnlist($user_id_main, $user_id_from);
    if (!empty($enlist)){

        dump($enlist);
        dump($this->Enlist->isActiveSub($user_id_main, $user_id_from));

        if ($enlist['active']) {

            $enlist -> active = 0;

            if($this->Enlist->save($enlist)) {
                dump($enlist);
            $this->Flash->success(__('Successfully UNENLISTED(1)!'));
            }
        } else {

            $enlist -> active = 1;

            if($this->Enlist->save($enlist)) {
                dump($enlist);
            $this->Flash->success(__('Successfully ENLISTED(1)!'));
            }
        }

    } else {
        $en = $this->Enlist->newEntity(['validate'=>'validationForEnlist']);
        $en['user_id_main'] = $user_id_main;
        $en['user_id_for'] = $user_id_from;
        $en['permited'] = 1;
        $en['active'] = 1;
       if ($this->Enlist->save($en)){
                $this->Flash->success(__('Successfully ENLISTED!'));
       }
    }
}

I would unset the active index on $enlist right after the conditional:

if ($enlist['active']) {
    unset($enlist['active']);
    $enlist -> active = 0;
    ...

} else {
    unset($enlist['active']);
    $enlist -> active = 1;
    ...
}

I'm guessing Cake is confused because you have both $enlist['active'] and $enlist->active. If that doesn't work, you could try setting active as an array, like

$enlist['active'] = 0;

instead of

$enlist -> active = 0;