andFilterWhere()函数找不出某个int类型字段为0的数据

首先本人刚接触YII2,  小知道都统计起来的。


andFilterWhere()函数找不出某个int类型字段为0的数据

$query = Equip::find()->andFilterWhere(['and','is_delete',0]);

该字段的值只有0和1。数据库中页确实存在该字段值为0的数据,但是这样写提示没有找到数据,把0改成1能找出该字段值为1的数据。如果不加andFilterWhere语句,那么会正常显示所有的数据,包括is_delete字段为0的数据。


先说解决办法, 改成下面的形式 :

$query = Equip::find()->andFilterWhere(['is_delete' => 0]);
或者
$query = Equip::find()->andFilterWhere(['and', ['is_delete' => 0]]);

接下来分析 为什么会出现这么有趣的现象

is_delete = 1 可以达到预期, 不加这个条件也可以达到预期, 偏偏 is_delete = 0 有问题


原因是按照你写的那样, 最终生成的sql会是 :

select * from table where is_delete and 0 (或者1);

有意思的是, select * from table where fieldName 这样的语句并不会报错.

我试了下, fieldName 为空, 为null, 为0的时候, 查不到.

其他时候均能查到, 但是此种情况下, 不会用到索引.


yii 数据model->save()相关

$this->model = Customer::model();
$client = $_POST['client'];
$this->model->attributes 
    =$client;
$this->model->create_user      =$create_user;
$this->model->create_date      =$create_date;
$this->model->save();
$customer_id =$this->model->attributes['id'];  //获取save插入后的id



上面是半年前写的,有不足,下面重新写着说明一下。

$ customer =Customer::model();
$post_data = $_POST['client'];
$
customer->attributes    =$ post_data;
$
customer->create_user    =Yii::app()->user->getId();
$
customer->create_time    =time();
$
customer->save();
$customer_id = $customer->id;  //这样获取save插入后的id最方便
$customer_id =$
customer->attributes['id']; //这样也可以 获取save插入后的id
$customer_info = $
customer->attributes;  //这样可以获取save插入后的相应model所有属性

直接 $this->model->id 不是更简单?

http://blog.sina.com.cn/s/blog_ea7f2ce40102wods.html        

yii model->save() 返回false

 yii model层操作总结 http://www.cnblogs.com/xieqian111/p/5212505.html

$model->save()执行时,如何不要验证?

public boolean save(boolean $runValidation=true, array $attributes=NULL)
$model->save(false);   //不验证


1.按钮的id为btnzhuce
==》 控制按钮为禁用:
$("#btnzhuce").attr({"disabled":"disabled"});
==》控制按钮为可用
 $("#btnzhuce").removeAttr("disabled");//将按钮可用



http://blog.csdn.net/dc769319/article/details/53022570    不修改源文件  直接 刷新验证码

http://www.yiichina.com/tutorial/410

http://www.360us.net/article/17.html    验证码的使用

https://segmentfault.com/a/1190000005910783  重写源生验证码



先设置 $model->allow_comment = 1
<?= $form->field($model, 'allow_comment')->checkbox([ 'label' => '允许评论']) ?>
这样这默认选中了








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值