English 中文(简体)
带有头部和细节的表单
原标题:Form with head and detail
  • 时间:2012-05-26 13:52:53
  •  标签:
  • atk4

不久前,我曾要求类似的东西, 但现在我接了这个,所以又问了一遍。

也许这个问题听起来很简单 但对我来说不是

我有两张桌子:

header (id,date,field1,field2) // This has One entry on the table
detail (id,idheader,field1,field2) // This can have multiple entries on the table

页眉 (1) - & gt; 细节 (N)

在相同的 $f-gt; 更新这两个表格上制作窗体和更新() 的最佳方法是什么?

想象一下,这可能有很多事情: 发票,预算,等等,等等

非常感谢

问题回答

看起来你的逻辑模型实际上位于两个表格中。 首先,决定哪个表格是“初级”表格, 也可以选择两种方式。 我将首先创建以下模式, 来制作“标题”表格 :

class Model_Header extends Model_Table {
    public $table= header ;
    function init(){
        parent::init();

        $this->addField( date )->type( date );
        $this->addField( field1 );
        $this->addField( field2 );
    }
}

接下来,您需要与第二个表格合并,并从中添加字段。当您调用 $model- gt;join () 时, 它会返回“ SQL_ relational” 对象, 该对象可以用来添加额外的字段并创建更多的加入。 您可以创建一个新对象或扩展您现有的对象 。

class Model_Record extends Model_Table {
    public $table= header ;
    function init(){
        parent::init();

        $this->addField( date )->type( date );
        $this->addField( field1 );
        $this->addField( field2 );

        $detail = $this->join( detail.idheader );
        $detail->addField( body );


        $details->addField( body_field1 , field1 );
    }
}

由于两个表格定义相同的字段和模型必须有一个独特的字段,我定义了一个用于细节的新名称.field1。我还明确指定了用于加入(idheader)的字段。接下来,你正在使用新模型,就像任何其他模式一样:

$form=$this->add( Form );
$form->setModel( Model_Record );
$form->onSubmit(function($form){
    $form->update()->js()->successMessage( success! )->execute();
});

传统做法是使用“标题”格子和增加“柱状扩展”格子,该格子显示“详细”格子,模型“细节”设置了Master Field(“标题”、$_GET[“标题_id”));

例如:

class page_test extends Page {
    function initMainPage(){
        $g = $this->add("Grid"); // or CRUD
        $g->setModel("header");
        $g->addColumn("expander", "details");
    }
    function page_details(){
        $this->api->stikcyGET("header_id");
        $g = $this->add("Grid"); // or CRUD
        $m = $this->add("Model_detail")->setMasterField("idheader", $_GET["header_id"]);
        $g->setModel($m);

    }
}

未测试。





相关问题
How to make a field "autocomplete"?

I can t figure out how to make a field autocomplete in ATK. I guess it has something to do with the type "reference" but still not sure. Suppose I m looking for a client name in a "line" type field, ...

How to create a "New xxx" popup?

I have a Grid object and added a [ (+) New Client ] button which I d like to open a popup form to create the new client with a couple fields. I ve looked at the code examples in the website but haven ...

Inline-editable fields goes away on clicking them

When I just load the page there are all the fields, but when I click on them, then the clicked field just disappears. However, no changes are applied to DB. This is the code: function ...

ATK4 and file upload

I am using controller_filestore and it gives error Method addCondition is not defined neither in controller_filestore, nor in its Model. If I use controller_filestore_image, it doesn’t find the class....

Help with atk4-web, atk4-example ver. 4.03

I don t now where can I find help. None forums about atk4. Can you help me, please? atk4-web (4.0.3): How run atk4-web localy, where is site dump (mysql database)? What is mean this error: No such ...

ATK4 - subfolder under page folder and js/css issue

I am using agile toolkit for one of my projects. When I create a sub folder under page folder, CSS and JS are not picked from atk4 folder and I have to copy those css and js under templates folder. Is ...

热门标签