指定的列不在行中

时间:2014-07-03 12:28:36

标签: php mysql zend-framework

我正在尝试检索表单,但每次尝试检索它时,我都会遇到此错误。

消息:指定的列“年”不在行

这是我的模型和表单代码。

模型

class Model_Periods extends Zend_Db_Table_Abstract
{
        protected $_name = 'periods';
        protected $_primary = 'id';

        public function getPeriods()
        {
            //ZEND Distinct Quite Illusive
            $select = $this->select()
            ->from($this, array('bus_year' => new Zend_Db_Expr('DISTINCT(bus_year)')))
            ->order('bus_year DESC');

            $results = $this->fetchAll($select);
            return $results;
        }

形式:

<?php

class Form_Targets extends Zend_Form
{

public function init()
{
    $available = $this->createElement('select', 'available');

    $available->setlabel('Select a year to continue');
    $available->setAttribs(array('class' => 'print the-font'));
    $available->addDecorators(array(array('HtmlTag',array('tag' => 'dd', 'class' => 'ui-select print the-font ui-print' ))));
    $available->setRequired(true);

    $pMdl = new Model_Periods();
    $periods = $pMdl->getPeriods();
    $available->addmultiOption(0, 'Year' );
    if ($periods->count() > 0)
    {
        foreach ($periods as $period)
        {
            $available->addmultiOption($period->year, $period->year);
        }
    }
    $this->addElement($available);

}

}

1 个答案:

答案 0 :(得分:1)

您收到此错误的原因是您在使用bus_year时在表格中包含名称为year的字段。所以换行

$available->addmultiOption($period->year, $period->year);

$available->addmultiOption($period->bus_year, $period->bus_year);