onunix 2012-05-10 14:01:01 2778次浏览 2条回复 0 0 0

我想把自动生成的一个页面表格中的列名变成中文, 这个页面是:http://localhost/Yii/index.php?r=otherExpenses/admin 里面是一个表格,找了下,估计对应于下面的代码:

<?php 
$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'otherexpenses-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'OtherExpensesID',
		'ServiceType',
		'depOrProfitName',
		'YearMonth',
		'Project',
		'AccountStatement',
		/*
		'BudgetAccount',
		'LocalCurrencyAmount',
		'BELUM',
		'MEMO',
		'CodeOfAccounts',
		'DataSource',
		*/
		array(
			'class'=>'CButtonColumn',
		),
	),
)); ?>

请问应该如何把列名变成中文。

  • 回复于 2012-05-10 16:06 举报
    <?php $this->widget('zii.widgets.grid.CGridView', array(
    
            'id'=>'otherexpenses-grid',
    
            'dataProvider'=>$model->search(),
    
            'filter'=>$model,
    
            'columns'=>array(
    
                    'OtherExpensesID',
                    
                    array(
                         'header'=>'类型',
                         'type'=>'raw',
                         'value'=>'$data->ServiceType',
                   ),
    
                    'depOrProfitName',
    
                    'YearMonth',
    
                    'Project',
    
                    'AccountStatement',
    
                    /*
    
                    'BudgetAccount',
    
                    'LocalCurrencyAmount',
    
                    'BELUM',
    
                    'MEMO',
    
                    'CodeOfAccounts',
    
                    'DataSource',
    
                    */
    
                    array(
    
                            'class'=>'CButtonColumn',
    
                    ),
    
            ),
    
    )); ?>
    
    
  • 回复于 2012-05-10 17:31 举报

    在models里

    public function attributeLabels(){
        return array(
            'id' => 'ID',
    	'name' => '名称',
        )
    }
    

    只要改这里相应的字段就可以了,如果要多语言就改成 'name' => Yii::t('site','名称') ,这种形式,然后翻译一下就可以了。

您需要登录后才可以回复。登录 | 立即注册