Yii2 adding an extra field to the form to add to database
On an existing project where there is a table with 3 fields (ID, name, label)
`id` int(11) NOT NULL,
`name` varchar(32) DEFAULT NULL,
`label` varchar(1) DEFAULT 'A'
Currently on the page where to add new record to the above table there is the form with only one field for the 'name', and works fine, and I need to add another field for the 'label' field; so I go to the related model (models/Products.php) and I have:
public function attributeLabels()
class Products extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'products';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name'], 'string', 'max' => 32],
[['name'], 'unique'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'name' => Yii::t('app', 'Name'),
];
}
I add the following to the above file, but no new input field is added to the form on the page
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'name' => Yii::t('app', 'Name'),
'label' => Yii::t('app', 'Prefix'),
];
}
I also tried adding to the rules like this, but no joy
public function rules()
{
return [
[['name', 'label'], 'string', 'max' => 32],
[['name', 'label'], 'unique'],
];
}
Appreciate if you can point me to what I am missing.
from Recent Questions - Stack Overflow https://ift.tt/3p6aLlI
https://ift.tt/eA8V8J
Comments
Post a Comment