Data Build
Last updated
Was this helpful?
Last updated
Was this helpful?
After you got your database setup thru , you proceed to define Data Build file.
Data Build is just a simple array file storing meta data to instruct Yee Code Generator on how to generate code for model and CRUD.
Refer to sample
module for the most complete Data Build example.
<?php
return array(
'pageTitle' => 'Sample',
'moduleCode' => 'sample',
'isAllowMeta' => true,
'isDeleteDisabled' => false,
'layout' => 'layouts.backend',
'menuTemplate' => array(
'index' => 'admin, create',
'admin' => 'create',
'create' => 'admin',
'update' => 'admin, create, view',
'view' => 'admin, create, update, delete',
),
'admin' => array(
'list' => array('id', 'title_en', 'sampleZone.label', 'image_main', 'gender', 'ordering', 'is_active', 'date_posted'),
'sortDefaultOrder' => 't.id DESC',
),
'structure' => array(
'code' => array(
'isUnique' => true,
'isUUID' => true,
),
'slug' => array(
'isUnique' => true,
),
'title_en' => array(
'label' => 'Title',
),
'sample_zone_code' => array(
'label' => 'Sample Zone',
),
'sample_zone_id' => array(
'isHiddenInForm' => true,
'isHiddenInSearch' => true,
'isHiddenInView' => true,
),
'gender' => array(
// define enum here, so generator can support database system that dont even supprot this data type such as sqlite
'isEnum' => true, 'enumSelections' => array('male' => 'Male', 'female' => 'Female', 'secret' => 'Secret'),
),
'image_main' => array(
'resize' => '320x240',
'hint' => 'Image will be automatically resize to 320x240 px.'
),
'external_code' => array(
'isNotForeignKey' => true, 'label' => 'External', 'hint' => 'camel case coded, e.g: abcXyz'
),
'latlong_address' => array(
'isSpatial' => true,
'isHiddenInForm' => true,
'isHiddenInSearch' => true,
'onChangeLinked' => array('full_address')
),
// in order for it to work as expected, this column must have a double database field
'ordering' => array('isHiddenInSearch' => true, ),
'json_extra' => array('isJson' => true),
'csv_keyword' => array('isCsv' => true),
),
'spatial' => array(
'latlong_address' => array(
'onChangeLinked' => array('full_address')
),
),
// this foreignKey is mainly for crud view generation. model relationship will not use this at the moment
'foreignKey' => array(
'sample_group_id' => array('relationName' => 'sampleGroups', 'model' => 'SampleGroup', 'foreignReferAttribute' => 'title_en'),
'sample_zone_code' => array('relationName' => 'sampleZone', 'model' => 'SampleZone', 'foreignReferAttribute' => 'label'),
),
'foreignRefer' => array('key' => 'code', 'title' => 'title_en'),
'json' => array(
'extra' => array(
'xxx' => array('label' => 'XXX'),
'yyy' => array('label' => 'YYY'),
)
),
/*
eg: resource (this table), industry(target table), resource2industry(linked table)
key: target table name, all small case singular form, eg 'industry'
className: the model name of target table, CamelCase with uppercase first character, eg 'Industry'
relationName: the MANY_MANY relations key generated by yii, all small case plural form of target table name, eg 'industries'
relationTable: the linked table name, eg 'resource2industry'
linkClassName: optional, if not provided, CamelCase with uppercase first character of relationTable, eg Resource2Industry
label: optional
isBigData: optional boolean, default: false. If set true, means the target table can be huge so the input method will be different
*/
'many2many' => array(
'sample_group' => array('className' => 'SampleGroup', 'relationName' => 'sampleGroups', 'relationTable' => 'sample_group2sample', 'linkClassName' => 'SampleGroup2Sample', 'isBigData' => false),
),
/*'tag' => array(
'skillsets' => array(
'tagTable' => 'tag', 'tagBindingTable' => 'tag2sample', 'modelTableFk' => 'sample_id', 'tagTablePk' => 'id', 'tagTableName' => 'name', 'tagBindingTableTagId' => 'tag_id', 'cacheID' => 'cacheTagSample'),
),*/
'csv' => array('csv_keyword'),
);