Tpextbuilder – displays [component] – use of with method

Time:2021-12-5

With

withyesfields,items,tab,stepGeneral methods in.

fieldsanditemsIf not usedwithMethod, need cooperationfieldsEnditemsEndending.

usewithThe ending method can be omitted(fieldsEnd、Itemend `) to make the code more hierarchical.

tab,stepNo explicit call is requiredendMethod, but it also supportswithmethod.

There are three ways to use:

    1. As variable parameters:

with($field1, $field2, $field3, $fieldN, );

    1. As an array element [as a compromise of 1, the variable parameter is followed by a number, which will report an error in lower versions of PHP and can be avoided in the array]

with([$field1, $field2, $field3, $fieldN, ]);

    1. As a statement in an anonymous method

with(function($form){$field1;$field2;$field3;$fieldN;});

The following code works correctly, where onlytabfieldsstepitemsSimilar.

$form->tab('tab1')->with(
    function () use ($form) {
        $form->fields('left1', '', 6)->size(0, 12)->showLabel(false)->with(
            function () use ($form) {
                $form - > text ('name ',' name ') - > required () - > MaxLength (55);
                $form - > tags ('keyword ',' keyword ');
                $form - > textarea ('description ',' summary ') - > MaxLength (255);
            }
        );

        $form->fields('right1', '', 6)->size(0, 12)->showLabel(false)->with(
            $form - > text ('name ',' name ') - > required () - > MaxLength (55),
            $form - > tags ('keyword ',' keyword '),
            $form - > textarea ('description ',' summary ') - > MaxLength (255), // note that the last number will report an error in lower versions of PHP. Delete or put fields in [] as an array
        );
    }
);

$form->tab('tab2')->with(
    //If you don't want to use use ($from), you can pass in parameters in an anonymous method
    //And declare the type: \ tpext \ builder \ common \ form (convenient for code editor prompt)
    //It is best to introduce: use tpext \ builder \ common \ form in the PHP file header; 
    //Then it can be abbreviated as: function (form $_form) {/ * code * /}
    //In the following code$_ Form and $form are the same thing. You can use one of them in practice.
    function (\tpext\builder\common\Form $_form) use ($form) {
        //left2 start
        $_form->fields('left2', '', 7)->showLabel(false)->size(0, 12);
        $_ Form - > number ('stock ',' inventory ') - > Default (99);
        $form - > number ('click ',' hits') - > Default (1);
        $form - > number ('sales_sum ',' sales') - > Default (0);
        $form->fieldsEnd();
        //left2 end
        //
        $form->fields('right2', '', 5)->size(0, 12)->showLabel(false)->with(
            [
                $_ Form - > text ('market_price ',' market price '),
                $form - > text ('cost_price ',' cost price '),
            ]
        );
    }
);

This work adoptsCC agreement, reprint must indicate the author and the link to this article