我的模型中只有该代码,因此,我得到了未定义的偏移量:0我应该怎么做才能解决这个问题?我尝试声明新变量,但仍然没有任何变化。谢谢
public function sendSMS() {
$model2 = SibuStudent::find()->innerJoin('Sibu_Payment', 'Sibu_Payment.virtual_id=Sibu_Student.virtual_id' )->where('Sibu_Student.phone1 != "NULL" ' ) ->all();
$model3 = SibuStudent::find()->innerJoin('Sibu_Payment', 'Sibu_Payment.virtual_id=Sibu_Student.virtual_id' )->where('Sibu_Student.student_name != "NULL" ' ) ->all();
$model4 = SibuPayment::find()->where('Sibu_Payment.total_payment != "NULL" ' )->all();
$model5 = SibuPayment::find()->where('Sibu_Payment.sms_status != "NULL" ')->all();
$count = sizeof($model2);
for($a=0; $a<5; $a++){
if ($model5[$a]->sms_status == 0) {
$no = $model2[$a]->phone1;
$message = 'Kepada Bapak/Ibu dari '.$model3[$a]["student_name"].',tagihan (SPP,Asrama,Kantin,Adm) Rp.'.$model4[$a]["total_payment"].' dibayarkan sesuai tagihan. SMS ini tidak untuk dibalas, jika ada yang kurang jelas diberitahukan kepada siswa dan menanyakan kepada kami. Salam';
if (strlen($message) < 160)
{
$outbox = new Outbox;
$outbox->CreatorID = 'Gammu';
$outbox->TextDecoded = $message;
$outbox->DestinationNumber = $no;
$outbox->save();
}
//batas for
}
}
您必须尝试这种方式才能从 MODEL 中查找NOT NULL
子句的数据。对所有检查非空条件的模型执行此操作。因为在这种情况下,您的模型没有具有键0
的元素,因此它返回Undefined offset 0
SibuPayment::find()->where(['not', ['Sibu_Payment.total_payment' => null]])->all();
例如 ['not', ['attribute' => null]] 将导致 条件不是(属性为空)
查看更多: http://www.yiiframework.com/doc-2.0/yii-db-query.html#where()-detail