【问题标题】:Calculated field always returns 1 - atk 4.2计算字段总是返回 1 - atk 4.2
【发布时间】:2012-04-24 04:05:16
【问题描述】:

我有一个具有计算字段的模型。返回的值始终为 1。打开调试后,查询中硬编码为 1:

<?php class Model_Income extends Model_base_Income {
    function init(){
        parent::init();
        $this->debug();
        $this->addField('year')->calculated(true);
    }
    function calculate_year(){
        return '22';
    }
}

调试返回的查询

    select `name`
,(select `name` from `client` where `income`.`client_id` = `client`.`id` )
`client`,`amount`,`date`,`comment`,1 `year`,`id` 
    from `income`

我正在使用 atk 4.2

【问题讨论】:

    标签: atk4


    【解决方案1】:

    在 4.2 中这样做:

    在模型中。

    $this->add("Field_Expression", "year")->set("22");
    

    或任何 sql 查询而不是 22。

    【讨论】:

    • 其实是 $this->addExpression('year')->set('22');但这只是一条捷径。
    • add("Field_XXX", $field_name) 很好,因为我们有更多花哨的字段类型,例如“filestore/Field_File”等。
    • 谢谢 romaninsh,当你说更多的时候,你有清单什么的吗?我看过这里link,但除了表情和参考之外,看不到其他人。
    • 是的,这里是文档链接:agiletoolkit.org/doc/modeltable/expression
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-16
    • 1970-01-01
    • 2016-11-21
    • 2019-10-10
    • 2014-04-13
    • 2017-03-20
    • 2013-11-04
    相关资源
    最近更新 更多