0

我会在一个字段中有 2 个自定义字段。我怎样才能做到这一点?


代码:

$criteria = new CDbCriteria;
$criteria->select='(number*2) AS custom_field, (number*4) AS custom_field';
$criteria->order='custom_field';
$model = Events::model()->findAll($criteria);

桌子:

number   custom_field
------------------
2         4, 8
3         6, 12

custom_field ordered -> 4, 6, 8, 12

编辑:

<?php $this->widget('bootstrap.widgets.TbGridView',array(
    'type'=>'striped bordered condensed',
    'id'=>'recurringevents-grid',
    'dataProvider'=>$model,
    'columns'=>array(
        'custom_field',
    ),
)); ?>

输出:

Custom Field
4
6
8
12
4

1 回答 1

1

第一个。事件.php

class Events extends CActiveRecord {
    public $custom_square, $custome_square_square;
// skip ...
    public funciton rules() {
    // skip ...
          array('custom_square, custom_square_square', 'safe'),

第二。单独的sql选择:

$criteria->select = array(
    new CDbExpression('(number*2) AS custom_square'), 
    new CDbExpression('(number*4) AS custom_square_square'),
);
$criteria->order='custom_square';
$model = Events::model()->findAll($criteria);
于 2013-01-16T05:12:42.617 回答