TABLE.label 不存在 YII,框架

TABLE.label doesnt exist YII, framework

我当时使用的是 YII 框架,我制作了模型,然后我使用了 Crud 生成器,我还使用 Crud 生成器制作了这些东西。 一切正常所以当我去 localHost/myprogram/index.php/myTable 我可以看到 table myTable。我的数据库中有 6 个 tables,它们相互连接,此页面适用于 5 个 tables,其中一个我得到了这个我以前没有得到的错误:

Property "DoePhaseThisTableName.label" is not defined.

在文件中:CActiveRecord.php(145)

return parent::__get($name);

CActiveRecord.php(145): CComponent->__get("label")

<?php echo CHtml::encode($data->label); ?>

我从 up 得到错误,还有这个:

exception 'CException' with message 'Property "DoePhaseThisTableName.label" is not
defined.' in C:\wamp\www\............\framework\base\CComponent.php:130

我不知道发生了什么,也不知道自从我上次检查它后它是如何正常工作的。有人可以帮我吗?

错误列表:

exception 'CException' with message 'Property "DoePhase.label" is not
defined.' in C:\wamp\www\momentum
technology\framework\base\CComponent.php:130
Stack trace:
#0 C:\wamp\www\momentum technology\framework\db\ar\CActiveRecord.php(145):
CComponent->__get('label')
#1 C:\wamp\www\testdrive\protected\views\doePhase\_view.php(13):
CActiveRecord->__get('label')
#2 C:\wamp\www\momentum technology\framework\web\CBaseController.php(130):
require('C:\wamp\www\tes...')
#3 C:\wamp\www\momentum technology\framework\web\CBaseController.php(95):
CBaseController->renderInternal('C:\wamp\www\tes...', Array, false)
#4 C:\wamp\www\momentum
technology\framework\zii\widgets\CListView.php(291):
CBaseController->renderFile('C:\wamp\www\tes...', Array)
#5 C:\wamp\www\momentum
technology\framework\zii\widgets\CBaseListView.php(181):
CListView->renderItems()
#6 [internal function]: CBaseListView->renderSection(Array)
#7 C:\wamp\www\momentum
technology\framework\zii\widgets\CBaseListView.php(164):
preg_replace_callback('/{(\w+)}/', Array, '{summary}?{sort...')
#8 C:\wamp\www\momentum
technology\framework\zii\widgets\CBaseListView.php(149):
CBaseListView->renderContent()
#9 C:\wamp\www\momentum technology\framework\web\CBaseController.php(181):
CBaseListView->run()
#10 C:\wamp\www\testdrive\protected\views\doePhase\index.php(20):
CBaseController->widget('zii.widgets.CLi...', Array)
#11 C:\wamp\www\momentum technology\framework\web\CBaseController.php(126):
require('C:\wamp\www\tes...')
#12 C:\wamp\www\momentum technology\framework\web\CBaseController.php(95):
CBaseController->renderInternal('C:\wamp\www\tes...', Array, true)
#13 C:\wamp\www\momentum technology\framework\web\CController.php(869):
CBaseController->renderFile('C:\wamp\www\tes...', Array, true)
#14 C:\wamp\www\momentum technology\framework\web\CController.php(782):
CController->renderPartial('index', Array, true)
#15
C:\wamp\www\testdrive\protected\controllers\DoePhaseController.php(128):
CController->render('index', Array)
#16 C:\wamp\www\momentum
technology\framework\web\actions\CInlineAction.php(49):
DoePhaseController->actionIndex()
#17 C:\wamp\www\momentum technology\framework\web\CController.php(308):
CInlineAction->runWithParams(Array)
#18 C:\wamp\www\momentum
technology\framework\web\filters\CFilterChain.php(133):
CController->runAction(Object(CInlineAction))
#19 C:\wamp\www\momentum technology\framework\web\filters\CFilter.php(40):
CFilterChain->run()
#20 C:\wamp\www\momentum technology\framework\web\CController.php(1145):
CFilter->filter(Object(CFilterChain))
#21 C:\wamp\www\momentum
technology\framework\web\filters\CInlineFilter.php(58):
CController->filterAccessControl(Object(CFilterChain))
#22 C:\wamp\www\momentum
technology\framework\web\filters\CFilterChain.php(130):
CInlineFilter->filter(Object(CFilterChain))
#23 C:\wamp\www\momentum technology\framework\web\CController.php(291):
CFilterChain->run()
#24 C:\wamp\www\momentum technology\framework\web\CController.php(265):
CController->runActionWithFilters(Object(CInlineAction), Array)
#25 C:\wamp\www\momentum technology\framework\web\CWebApplication.php(282):
CController->run('')
#26 C:\wamp\www\momentum technology\framework\web\CWebApplication.php(141):
CWebApplication->runController('doePhase')
#27 C:\wamp\www\momentum technology\framework\base\CApplication.php(184):
CWebApplication->processRequest()
#28 C:\wamp\www\testdrive\index.php(13): CApplication->run()
#29 {main}
REQUEST_URI=/testdrive/index.php/doePhase

doePhae.php

<?php

/**
 * This is the model class for table "doe_phase".
 *
 * The followings are the available columns in table 'doe_phase':
 * @property string $id
 * @property string $label
 * @property string $description
 */
class DoePhase extends CActiveRecord
{
    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'doe_phase';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('label, description', 'length', 'max'=>45),
            // The following rule is used by search().
            // @todo Please remove those attributes that should not be searched.
            array('id, label, description', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'label' => 'Label',
            'description' => 'Description',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     *
     * Typical usecase:
     * - Initialize the model fields with values from filter form.
     * - Execute this method to get CActiveDataProvider instance which will filter
     * models according to data in model fields.
     * - Pass data provider to CGridView, CListView or any similar widget.
     *
     * @return CActiveDataProvider the data provider that can return the models
     * based on the search/filter conditions.
     */
    public function search()
    {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id,true);
        $criteria->compare('label',$this->label,true);
        $criteria->compare('description',$this->description,true);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }

    /**
     * Returns the static model of the specified AR class.
     * Please note that you should have this exact method in all your CActiveRecord descendants!
     * @param string $className active record class name.
     * @return DoePhase the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
}

您的 table 结构有误。

在 table doe_phase 的屏幕上你有字段 'lavel',而在模型中你显然期望 'label'

 * @property string $label

只要在 table 中修改属性名称就可以了。

希望对您有所帮助。