The argument is not iterable()

I made a model Validator that checks the uniqness of a model by multiple fields

namespace AutoPoster\Backend\Validators;


use Phalcon\Mvc\Model\Validator;
use Phalcon\Mvc\Model\ValidatorInterface;

class UniqueFields extends Validator implements ValidatorInterface{

    public function validate($model){

        $fields = $this->getOption('fileds');
        if(!is_array($fields)){
            return false;
        }

        $conditions = "";
        $binds = array();
        $i=0;
        foreach($fields as $field){

            $i++;

            if($i>1)
                $conditions.=' AND ';

            $conditions .= $field.' = '.$i.'?';
            $binds[] = $model->$field;

        }

        if($model::findFirst(array(
            'conditions' => $conditions,
            'bind' => $binds
        ))){

            $this->appendMessage(
                $this->getOption('message'),
                'Fileds',
                'UniquePlanificationValidator'
            );

            return false;
        }

        return true;
    }
}

in the validation function of a model I did:

$this->validate(new UniqueFields(array(
                'fields' => array('datePublication', 'Articles_id'),
                'message' => 'Planification already exists',
            )
        ));

I got this error:

Fatal error: The argument is not iterable() in <MY DIR>\app\backend\models\Planifications.php on line 60



13.7k

No one can help ?

What's line 60?



13.7k

@quasipickle the line 60 is in the model validation function:

$this->validate(new UniqueFields(array(
                'fields' => array('datePublication', 'Articles_id'),
                'message' => 'Planification already exists',
            )
        ));

There's nothing on that line that iterates - are you sure the error isn't in your validator class?

I do also see some strings called "Fileds" - is that a typo? Should those strings be "Fields"?