【问题标题】:TABLE.label doesnt exist YII, frameworkTABLE.label 不存在 YII,框架
【发布时间】:2015-07-24 08:39:52
【问题描述】:

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

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

我从上面得到了错误,还有这个:

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

【问题讨论】:

  • DoePhaseThisTableName, DoePhase, ... 这些是类的实际属性吗?
  • @Masiorama DoePhaseThisTableName 不是,但另一个是表的名称。
  • 我认为您应该检查给您错误的表的实际结构以及您通过 gii 生成的模型。肯定有一些差异,即使只是拼写错误。
  • @Masiorama Idid 检查它,我也删除了那些生成的文件,我再次制作它,但同样的问题。
  • 你能把你生成的表结构和模型贴出来吗?

标签: php database database-design yii localhost


【解决方案1】:

您的表结构有误。

从 doe_phase 表的屏幕中,您可以看到字段“lavel”,而在模型中您显然希望看到“label”

 * @property string $label

只要把表中的属性名改正就行了。

希望对你有帮助。

【讨论】:

  • 非常感谢,我想使用 Level 而不是 Lebel,这是拼写错误。谢谢你的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-16
  • 2015-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多