octobercms/october · error · SystemException

The model class :model must define a method :method()…

Error message

The model class :model must define a method :method() returning options for the ':field' form field.

What it means

Thrown by FormField::getOptionsFromModelAsString when a form field's options reference a model instance method that is not defined on the model class. The field config names a method expected to supply dropdown options; the model lacks it, so option resolution fails at render time.

Solutions

  1. Add the named public method to the model returning an array of options
  2. Correct the method name in the field definition's options key
  3. Use an explicit array of options or a ClassName::method static reference if the data is static
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/backend/classes/FormField.php:545 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/0de24ca857bf788c. Report an issue: GitHub.

Appendix: source

Thrown at modules/backend/classes/FormField.php:545

     * getOptionsFromModelAsString where options are an explicit method reference
     */
    protected function getOptionsFromModelAsString($model, string $methodName, $data)
    {
        // Calling via ClassName::method
        if ($callableMethod = $this->getCallableMethodFromValue($methodName)) {
            $fieldOptions = $callableMethod($model, $this);

            if (!is_array($fieldOptions)) {
                throw new SystemException(Lang::get('backend::lang.field.options_static_method_invalid_value', [
                    'class' => $callableMethod[0],
                    'method' => $callableMethod[1]
                ]));
            }
        }
        // Calling via $model->method
        else {
            if (!$this->objectMethodExists($model, $methodName)) {
                throw new SystemException(Lang::get('backend::lang.field.options_method_not_exists', [
                    'model' => get_class($model),
                    'method' => $methodName,
                    'field' => $this->fieldName
                ]));
            }

            $fieldOptions = $model->$methodName($this->value, $this->fieldName, $data);
        }

        return $fieldOptions;
    }

    /**
     * getOptionsFromModelAsDefault refers to the model method or any of its behaviors
     */
    protected function getOptionsFromModelAsDefault($model, $data)
    {
        try {

View on GitHub (pinned to b608633a7e)