Model and its behaviors do not have a method or closure named "optgroup" I'm attempting to finish my first fieldtype plugin (how exciting!) but having an issue with displaying options in a select dropdown in an entry.

My ColumnWidth_WidthsFieldType has this:

&lt;?php

namespace Craft;

/**
 * Widths Fieldtype
 *
 * Allows entries to select associated widths
 */
class ColumnWidth_WidthsFieldType extends BaseFieldType
{
    /**
     * Get the name of this fieldtype
     */
    public function getName()
    {
        return Craft::t('Column Widths');
    }

    /**
     * Get this fieldtype's column type.
     *
     * @return mixed
     */
    public function defineContentAttribute()
    {
        // "Mixed" represents a "text" column type, which can be used to store arrays etc.
        return AttributeType::Mixed;
    }

    /**
     * Get this fieldtype's form HTML
     *
     * @param  string $name
     * @param  mixed  $value
     * @return string
     */
    public function getInputHtml($name, $value)
    {
        // call our service layer to get a current list of widths
        $widths = craft()-&gt;columnWidth_widths-&gt;getAllWidths();

        // create an array for the widths 
        $widthsOptions = array();

        // populate the $widthsOptions array with $widths
        foreach ($widthsOptions as $widths )
        {
            $widthsOptions[$widths-&gt;id] =  $widths-&gt;name;
        }

        return craft()-&gt;templates-&gt;render('columnwidth/_fieldtypes/widths', array(
            'name'      =&gt; $name,
            'values'    =&gt; $value,
        ));
    }
}


My columnwidth/_fieldtypes/widths has this:

{% import "_includes/forms/" as forms %}
​
{% set widths = craft.columnwidth.getAllWidths %}

{{ forms.selectField({
    instructions: "Select the width of your column"|t,
    id: 'columnWidth',
    name: 'columnWidth',
    options: widths
}) }}


But I'm getting this error:

Craft\ColumnWidth_WidthsModel and its behaviors do not have a method or closure named "optgroup".

The only post I found was here:

Displaying a list of fields in a form select

I'm sure I'm missing something and any help is appreciated!
Few things - you need to add the options to the render function so they are passed into the template. Also, check what I did below for the $widthsOptions. Each option needs a label and value key/value pair.

public function getInputHtml($name, $value)
{
    // call our service layer to get a current list of widths
    $widths = craft()-&gt;columnWidth_widths-&gt;getAllWidths();

    // create an array for the widths 
    $widthsOptions = array();

    // populate the $widthsOptions array with $widths
    foreach ($widths as $width )
    {
        $widthsOptions[] = array(
            'label' =&gt; $width-&gt;name, //this should be whatever you want to display in dropdown
            'value' =&gt; $width-&gt;name //this should be the value you want passed to the database
        );
    }

    return craft()-&gt;templates-&gt;render('columnwidth/_fieldtypes/widths', array(
        'name'      =&gt; $name,
        'values'    =&gt; $value,
        'options'   =&gt; $widthsOptions
    ));
}


Your field type template should be something like this:

{% import "_includes/forms/" as forms %}
​
{{ forms.selectField({
    instructions: "Select the width of your column"|t,
    id: 'columnWidth',
    name: 'columnWidth',
    options: options,
    value: values
}) }}