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

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

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

模型

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);

}

}

最佳答案

之所以收到此错误,是因为使用bus_year时表中包含名称为year的字段。所以换线

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




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

关于php - 指定的列不在行中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24553709/

10-11 03:14