简体   繁体   中英

CakePHP 3.0 - helper - form label from field definition

Is there a way to make the CakePHP bake command assign the field description (as it is on the database) as the labels of a form?

For example, if the table definition is as follows:

CREATE TABLE `equipment` (
  `equ_pk` int(11) NOT NULL AUTO_INCREMENT,
  `equ_desc` varchar(60) NOT NULL COMMENT 'Description',
  `equ_code` varchar(10) NOT NULL COMMENT 'Code',
  PRIMARY KEY (`equ_pk`),
  UNIQUE KEY `equ_code_UNIQUE` (`equ_code`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Then in the labels of the form would be "Description" and "Code".

By default, the bake command make them "equ_desc" and "equ_code".

I don't believe this is possible with bake as it sounds like a rather bespoke situation (someone correct me if I'm wrong). However, you can alter your baked forms and override the labels generated using the label option on the form inputs like this:-

<?= $this->Form->input('equ_desc', ['label' => __('Description')]) ?>

This would give you the desired labels.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM