对于每个循环连续但不填充数组

问题

Hey, my array $isActiefErr and $naamErr doesn't fill up after I throw an exception, but the foreach loop does continue to validate the values. I know the foreach loop keeps on looping, because the array with values are all filled, but the error array stops after the first error.

我尝试过的

I've tried to print the array but it only pushes the first error into my array. It then stops validating. This also shows in my error log. I think the problem would be the try/catch, but I simply cannot confirm this, because of my lack of knowledge regarding try/catches.

我怎样才能让数组推入并用围绕它的try / catch块显示所有错误?还是我只是错过了一些东西,并且不是与尝试/捕获有关的问题吗?

这是我的代码:

$validateOk = 0;
$setVar = new SetVariable();

$teller = 1;
$save = null;
$validateOk = 0;

$con->beginTransaction();
$weg = TypeQuery::create()->find();
$weg->delete();
try {
    foreach ($_POST as $key => $value) {
        if (isEven($teller)) {
            $validateOk += $setVar->nameval($key)
                ->onerror($isActiefErr[]) //errors aren't being pushed into this array, besides the first one.
                ->validator(v::numericVal())
                ->go();
            if ($validateOk == 0) {
                $save->setCode(substr($key, 1));
                $save->setIsActief($value);
                $save->save();
            } else {
                //ROLLBACK/CATCH
                throw new Exception($error);
            }
        } else {
            $validateOk += $setVar->nameval($key)
                ->onerror($naamErr[])
                ->validator(v::alpha('/()éá&.,   '))
                ->go();
            if ($validateOk == 0) {
                $save = new Type();
                $save->setCode(substr($key, 1));
                $save->setNaam($value);
            } else {
                //ROLLBACK/CATCH
                throw new Exception($error);
            }
        }
        $teller += 1;
    }
    $con->commit();
} catch (Exception $e) {
    $error = "Het opslaan is fout gegaan!";
} {
    $con->rollback();
}

}

评论