Types to add in field from database Agile Toolkit

647 Views Asked by At

I've discovering Agile Toolkit and I have problem with finding addField('field')->type(). What kind of types could there be and where can I find them? I need type 'set', but addField('field')->type('set') is not working.

Thank you in advance.

2

There are 2 best solutions below

0
On

The best source for types of fields that I have found is here:

ATK4 API Reference

Of course, I am less that a month into ATK4 and is a good starting point. The examples supplied with ATK4 are helpful and the Jobeet example has some good info. Dive in!

0
On

ATK4 is distributed with simple usable basic types which is limited to the following list:

  • string
  • date
  • datetime
  • text
  • int
  • real
  • boolean
  • password
  • list

As for the set type, the nearest would be that of a list type.

example:

 $this->addField('month')->type('list')->caption('Month')
    ->listData(array(
        1 => 'Jan',
        2 => 'Feb',
        3 => 'Mar',
        4 => 'Apr',
        5 => 'May',
        6 => 'Jun',
        7 => 'Jul',
        8 => 'Aug',
        9 => 'Sep',
       10 => 'Oct',
       11 => 'Nov',
       12 => 'Dec'));

also, there is a special treatment to boolean types in ATK4 Models and does not directly correspond to the same boolean type in MySQL which is simply equivalent to TINYINT(1).

in order to make use of a type boolean for a table field in ATK4, it has to be declared as an enum('Y','N') and prepended with an is_ on its field name.

example:

 CREATE TABLE foo (
 id INT(11) NOT NULL AUTO_INCREMENT,
 :
 is_active ENUM('Y','N') NOT NULL DEFAULT 'Y',
 :
 PRIMARY KEY (id)
 ) DEFAULT CHARSET=utf8;

with this, the MVCGrid, MVCForm and CRUD can treat the is_active as a special field and be displayed as a graphical check mark on grids and a check box button on forms.