0

在 CrudeCode.php 中,我注释掉了第 69-70 行,并使用 Gii 创建了我的模型,它有 2 个复合键作为主键。现在当我浏览到页面时出现错误

2012/09/19 09:50:29 [error] [exception.CException] exception 'CException' with message 'Property "ComAsset.Array" is not defined.' in /opt/dam/yii-1.1.12.b600af/framework/base/CComponent.php:131
Stack trace:
#0 /opt/dam/yii-1.1.12.b600af/framework/db/ar/CActiveRecord.php(144): CComponent->__get('Array')
#1 /opt/dam/protected/views/comAsset/_view.php(9): CActiveRecord->__get('Array')
#2 /opt/dam/yii-1.1.12.b600af/framework/web/CBaseController.php(131): require('/opt/dam/protec...')
#3 /opt/dam/yii-1.1.12.b600af/framework/web/CBaseController.php(96): CBaseController->renderInternal('/opt/dam/protec...', Array, false)
#4 /opt/dam/yii-1.1.12.b600af/framework/zii/widgets/CListView.php(260): CBaseController->renderFile('/opt/dam/protec...', Array)
#5 /opt/dam/yii-1.1.12.b600af/framework/zii/widgets/CBaseListView.php(161): CListView->renderItems()
#6 [internal function]: CBaseListView->renderSection(Array)
#7 /opt/dam/yii-1.1.12.b600af/framework/zii/widgets/CBaseListView.php(144): preg_replace_callback('/{(\w+)}/', Array, '{summary}?{sort...')
#8 /opt/dam/yii-1.1.12.b600af/framework/zii/widgets/CBaseListView.php(129): CBaseListView->renderContent()
#9 /opt/dam/yii-1.1.12.b600af/framework/web/CBaseController.php(174): CBaseListView->run()
#10 /opt/dam/protected/views/comAsset/index.php(20): CBaseController->widget('zii.widgets.CLi...', Array)
#11 /opt/dam/yii-1.1.12.b600af/framework/web/CBaseController.php(127): require('/opt/dam/protec...')
#12 /opt/dam/yii-1.1.12.b600af/framework/web/CBaseController.php(96): CBaseController->renderInternal('/opt/dam/protec...', Array, true)
#13 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(870): CBaseController->renderFile('/opt/dam/protec...', Array, true)
#14 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(783): CController->renderPartial('index', Array, true)
#15 /opt/dam/protected/controllers/ComAssetController.php(128): CController->render('index', Array)
#16 /opt/dam/yii-1.1.12.b600af/framework/web/actions/CInlineAction.php(50): ComAssetController->actionIndex()
#17 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(309): CInlineAction->runWithParams(Array)
#18 /opt/dam/yii-1.1.12.b600af/framework/web/filters/CFilterChain.php(134): CController->runAction(Object(CInlineAction))
#19 /opt/dam/yii-1.1.12.b600af/framework/web/filters/CFilter.php(41): CFilterChain->run()
#20 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(1146): CFilter->filter(Object(CFilterChain))
#21 /opt/dam/yii-1.1.12.b600af/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))
#22 /opt/dam/yii-1.1.12.b600af/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(Object(CFilterChain))
#23 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(292): CFilterChain->run()
#24 /opt/dam/yii-1.1.12.b600af/framework/web/CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array)
#25 /opt/dam/yii-1.1.12.b600af/framework/web/CWebApplication.php(283): CController->run('')
#26 /opt/dam/yii-1.1.12.b600af/framework/web/CWebApplication.php(142): CWebApplication->runController('comAsset')
#27 /opt/dam/yii-1.1.12.b600af/framework/base/CApplication.php(162): CWebApplication->processRequest()
#28 /opt/dam/index.php(13): CApplication->run()
#29 {main}
REQUEST_URI=/dam/index.php?r=comAsset

我已经在 yii 论坛上搜索并查看过,但找不到任何关于如何在 yii 1.1.12 中实现复合键的明确文档。谁能详细说明。

在我的模型中,我包含了主键功能

public function primaryKey()
{
    //return 'id';
    // For composite primary key, return an array like the following
    return array('fixed_asset', 'component');
}

/**
     * @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(
            'fixedAsset0' => array(self::BELONGS_TO, 'FixedAsset', 'fixed_asset'),
            'component0' => array(self::BELONGS_TO, 'Components', 'component_id'),
        );
    }

在 fixed_asset 表中,主键是fixed_assetcomponent。这也是component_idcomponents 表和fixed_asset_idfixed_asset 表中的外键。我的关系和主键对吗?

4

0 回答 0