0

Help me!!! Thank all. I'm using Yii2 Advanced and I'm getting this error, i dont know fix:

PHP Notice – yii\base\ErrorException Trying to get property 'madinhdanh' of non-object

I'm want search "linhvucchuyennganh" by "madinhdanh". My code:

if (!empty($this - > linhvucchuyennganh)) {

    $linhvuc = Lvtc::find() - > andWhere(['=', 'madinhdanh', $this - > linhvucchuyennganh]) - > one();
    if (1 == 2 && ($linhvuc - > maphanloai == null || $linhvuc - > maphanloai == '')) {
        $linhvuclist = Lvtc::find() - > select(['madinhdanh', 'tieuchuan']) - > andWhere(['=', 'maphanloai', $linhvuc - > madinhdanh]) - > all();
        $arrchild = \yii\ helpers\ ArrayHelper::map($linhvuclist, 'madinhdanh', function($model) {
            return $model['tieuchuan'];
        });
        $arrTCID = array();
        if (!empty($arrchild)) {
            foreach($arrchild as $child) {
                if (!empty($child)) {
                    if (empty($arrTCID)) $arrTCID = $child;
                    else $arrTCID = array_merge($arrTCID, $child);
                }
            }
        }
        if (!empty($arrTCID)) {
            $query - > andWhere(['tc_id' => $arrTCID]);
        } else {
            $query - > andWhere(['=', "CONCAT('1','')", '2']);
        }
    } else {
        $arrcode = explode('.', $linhvuc - > madinhdanh);
        if (!empty($arrcode)) {
            $html = '';
            foreach($arrcode as $code) {
                if ($code == '00' || intval($code) == 0) {
                    break;
                } else {
                    if ($html == '') $html = $code;
                    else $html. = '.'.$code;
                }

            }
            if (!empty($html)) {
                $querytmp = Lvtc::find() - > select(['madinhdanh', 'tieuchuan']) - > andWhere(['or', ['LIKE', 'madinhdanh', $html.'.%', false],
                    ['=', 'madinhdanh', $linhvuc - > madinhdanh]
                ]);
                $linhvuclist = $querytmp - > all();
                $arrchild = \yii\ helpers\ ArrayHelper::map($linhvuclist, 'madinhdanh', function($model) {
                    return $model['tieuchuan'];
                });
                $arrTCID = array();
                if (!empty($arrchild)) {
                    foreach($arrchild as $child) {
                        if (!empty($child)) {
                            if (empty($arrTCID)) $arrTCID = $child;
                            else $arrTCID = array_merge($arrTCID, $child);
                        }
                    }
                }
                if (!empty($arrTCID)) {
                    $query - > andWhere(['tc_id' => $arrTCID]);
                } else {
                    $query - > andWhere(['=', "CONCAT('1','')", '2']);
                }
            } else {
                $query - > andWhere(['=', "CONCAT('1','')", '2']);
            }
        } else {
            $query - > andWhere(['=', "CONCAT('1','')", '2']);
        }
    }
}
Serghei Leonenco
  • 3,478
  • 2
  • 8
  • 16
JackieLino
  • 23
  • 8
  • 1
    Try to use at the begging of your `query` NOT `andWhere` but `where`. Change to look like this: `Lvtc::find()->where(['=', 'madinhdanh', $this->linhvucchuyennganh])->one();` – Serghei Leonenco Aug 11 '20 at 04:20
  • Also can you post your model `Lvtc` ? – Serghei Leonenco Aug 11 '20 at 04:22
  • Does this answer your question? [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Nico Haase Aug 12 '20 at 09:48

0 Answers0