【问题标题】:Reference Table Lookup Ability in Agile Toolkit ATK4 CRUD敏捷工具包 ATK4 CRUD 中的参考表查找能力
【发布时间】:2012-01-13 12:48:51
【问题描述】:

我需要敏捷工具包 CRUD 网格/表单方面的帮助。

我在敏捷工具包中为员工、职位和部门制作了一个 CRUD 网格/表格。 这很容易。但我现在很难设置位置和 部门栏目。我不想显示“id”值,而是显示引用的 'pos_desc' 和 'dept_desc' 中的文本。

同样在 CRUD 的添加/编辑表单中,它只显示 'id' 而不是相应的文本。 有没有办法使用描述文本设置它,但保存'id' 提交时?

谢谢!

这里是项目的目录结构和一些代码sn-ps:

    + atk4
    + atk4-addons
    + empmaster
      + admin
        + lib
        + page
      + doc
      + lib
        + Model
      + page
      + templates

admin/lib/Admin.php

    class Admin extends ApiFrontend {
    :
    :   
       function init(){
    :
    :
          $this->addLocation('..',array(
                      'php'=>array(
                            'lib',
                            )
                      ));
          $this->addLocation('../..',array(
                      'php'=>array(
                            'atk4-addons/mvc',
                            'atk4-addons/misc/lib',
                            )
                      ))
                ->setParent($this->pathfinder->base_location);
    :
    :

lib/Model/Employee.php

    class Model_Employee extends Model_Table {
       public $entity_code = 'emp';

       function init() {
          parent::init();

          $this->addField('eeid')->caption('Emp ID');
          $this->addField('fnm')->caption('First Name');
          $this->addField('mnm')->caption('Middle Name');
          $this->addField('lnm')->caption('Last Name');

          $pos=$this->addField('pos_id')->caption('Position');
          $pos->refModel('Model_Postition');

          $dep=$this->addField('dept_id')->caption('Department');
          $dep->refModel('Model_Department');

          // #1 refModel gives error if declared w/out 'Model_' prefix
          // #2 Position & Department caption not on grid, but only on form
       }
    }

lib/Model/Position.php

    class Model_Position extends Model_Table {
       public $entity_code = 'pos';

       function init() {
          parent::init();

          $this->addField('pos_desc');
       }
    }

lib/Model/Department.php

    class Model_Department extends Model_Table {
       public $entity_code = 'dept';

       function init() {
          parent::init();

          $this->addField('dept_desc');
       }
    }

admin/page/index.php

    $crud = $tabs->addTab('Employee Master')->add('CRUD')->setModel('Employee');

【问题讨论】:

    标签: forms grid crud atk4 agiletoolkit


    【解决方案1】:

    默认情况下,它会在模型​​上查找名为“name”的字段。如果您没有此字段,则需要覆盖 Model_Position 中的 toStringSQL 函数。

    有关更多信息,请参阅此答案:

    reference field on form

    【讨论】:

    • 是的!你提到的链接就像一个魅力。非常感谢!我知道敏捷工具包学习部分的模型介绍中特别提到的“名称”字段,我一定忽略了它,因为它说:默认情况下,会考虑名为“名称”(如果已定义)的字段一个“显示字段”。当您使用书籍模型构建网格时,您将看到该相关表的“名称”。
    • 我认为这意味着,获取表的名称。我将这两个模型分别更改为:$this->addField('name')->caption('Position');$this->addField('name')->caption('Department'); 并将字段“pos_desc”和“dept_desc”重命名为“name”。再次感谢您提供这个精彩的框架!我会尽可能提供反馈。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2021-12-02
    • 2012-10-05
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    相关资源
    最近更新 更多