duanhan8757 2019-05-02 03:21
浏览 9

登记活动提交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!'));
       }
    }
}
  • 写回答

1条回答 默认 最新

  • dpzp5127 2019-05-02 13:28
    关注

    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;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集