dongyao8698 2018-07-31 21:22
浏览 48

删除Yii Model中的属性集

I work with Yii 1.x integrated with an LDAP database and while I was developing an feature for external user access to IT resources: Domain (to authenticate Windows/Linux external users) and Wi-fi (access to use), or both.

I faced a scenario where I need to remove an attribute which I earlier set in the model: for security reasons, I populate the model with all data expect the main flags like sambaAcctFlags, disabledAccount and shadowExpire whom grant real access to resources: SAMBA in Domain and RUCKUS in Wi-fi.

The main problem is when I create a model record, I set the attribute disabledAccount - which when not there grants access to Wi-fi, but when its set the RUCKUS refuses auth - and now I cannot remove this value from model when the user has not selected the checkbox and so I tried to use unset($model->disabledAccount) and it didn't work. I have seen some suggestions that replace the variable with a null value but with my LDAP Yii' extensions, this will throw an LDAP error when saving the disabledAccount attribute.

Any light what could be done?

                $model->shadowexpire = time();
                $model->sambaAcctFlags = '[UD]';
                $model->disabledaccount = date('YmdHis\Z');

                foreach ($_POST['checkbox_acessos'] as $access ) {
                    switch ($access) {
                        case 'C': // Verify if the user has set Domain Access to user
                            $model->sambaAcctFlags = '[U]';   //Change flag from Deactivate to Activate
                            break;
                        case 'W': // Verify if the user has set Wi-fi to user
                            unset($model->disabledaccount); //this is the main problem**
                            echo "Wi-fi Granted!";
                            break;           
                    }
                }

                $model->shadowExpire = strtotime($validade->format('d-m-Y H:i:s'));
                // Date when Expire Unix based systems access
  • 写回答

1条回答 默认 最新

  • dongpang1898 2018-07-31 21:39
    关注

    I can't get your problem correctly, your sentences were incomplete, anyway if you want to save the default value that you defined before in your database, replace unset method with unsetAttributes().

    In this case:

    $model->unsetAttributes(['disabledAccount']);
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)