是否可以在MVC网格中使用“内联”字段?

时间:2012-02-06 04:48:25

标签: atk4

是否可以在MVC网格中使用“内联”字段? 怎么样? 我尝试过几种可以想象的方式:

$g=$this->add('MVCGrid');
$g->setModel('ProgramaPago');                
$g->addColumn('inline','temp_pago');
$g->dq->where('alumno_id',$_GET['id']);

显示,但如果尝试编辑,则会收到SQLException错误,如:

  

无法执行查询:update programaPago pp set temp_pago = 34   where(alumno_id ='1')和(programaPago pp.id ='1')

但是我可以想出来......再次感谢

以下是我参与的模型:

class Model_ProgramaPago extends Model_Table {
public $entity_code='programaPago';
public $table_alias='pp';
function init(){
    parent::init();

    $this->addField('alumno_id')->caption('Alumno')->refModel('Model_Alumno')->mandatory(true);
    $this->addField('fechaVencimiento')->caption('Fecha de Vencimiento')->type('date')->mandatory(true);
    $this->addField('concepto')->caption('concepto')->type('text')->mandatory(true);
    $this->addField('monto')->caption('Monto')->type('money')->mandatory(true);
    $this->addField('montoPagado')->caption('Monto Pagado')->type('money')->calculated(true);
    $this->addField('montoPendiente')->caption('Monto Pendiente')->type('money')->calculated(true);
    $this->addField('temp_pago')->caption('Este Pago')->type('money')->mandatory(true);
}
function calculate_montoPagado(){
    return "SELECT SUM( caja.monto ) FROM caja  WHERE caja.programaPago_id =".
            ($this->table_alias?:$this->entity_code).
            ".id";
}

function calculate_montoPendiente(){

    return "(SELECT ( programaPago.monto - COALESCE(iTotal.TotalMonto,0)) Result
            FROM programaPago LEFT JOIN 
            (SELECT programaPago_id, SUM(monto) as TotalMonto
            FROM caja GROUP BY programaPago_id) as iTotal
            ON programaPago.ID = iTotal.programaPago_id
            WHERE programaPago.ID =".
            ($this->table_alias?:$this->entity_code).
            ".id)";

}

}

这是从计算功能调用的一个beiing:

class Model_Caja extends Model_Table {
public $entity_code='caja';
public $table_alias='c';
function init(){
    parent::init();

    $this->defineAuditFields();

    $this->addField('concepto')->caption('Concepto')->mandatory(true);
    $this->addField('monto')->type('money')->caption('Monto')->mandatory(true);
    $this->addField('programaPago_id')->refModel('Model_ProgramaPago');
}
}

0 个答案:

没有答案