TABLE.label不存在YII,框架

时间:2022-06-11 10:41:31

I was working with YII framework, I made the models and then I used the Crud generator and I also made those things using Crud generator. Everything works fine so when I go to localHost/myprogram/index.php/myTable I can see the table myTable. I have 6 tables in my Database and they are connected to each other, This page works for 5 tables and for one of them I get this error that I wasnt getting before:

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

Property "DoePhaseThisTableName.label" is not defined.

In the file: CActiveRecord.php(145)

在文件中:CActiveRecord.php(145)

return parent::__get($name);

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

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

I get the errors from up and also this:

我从错误中得到了错误:

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

I have no idea what has hapened and how since last time I check it was working correctly. can someone maybe help me out here?

我不知道自从上次检查它是否正常工作以来已经发生了什么。有人可以帮帮我吗?

list of errors:

错误列表:

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

1 个解决方案

#1


You have an error in your table structure.

表结构中有错误。

From the screen of the table doe_phase you have the field 'lavel', while in the model you clearly expect 'label'

在doe_phase表的屏幕上你有“lavel”字段,而在模型中你清楚地期望'label'

 * @property string $label

Just fix the name of the attribute in the table and you should be good.

只需在表格中修复属性的名称即可。

Hope it helps.

希望能帮助到你。

#1


You have an error in your table structure.

表结构中有错误。

From the screen of the table doe_phase you have the field 'lavel', while in the model you clearly expect 'label'

在doe_phase表的屏幕上你有“lavel”字段,而在模型中你清楚地期望'label'

 * @property string $label

Just fix the name of the attribute in the table and you should be good.

只需在表格中修复属性的名称即可。

Hope it helps.

希望能帮助到你。