How do I pass this form value
<?= $form->field($directions, 'product_directions')->hint('Use the custom tag <bull> to create a bullet and use <rtn> to break lines.')->textarea(['rows' => 6]) ?>
into my model’s beforeSave() function?
namespace app\models;
use Yii;
/**
* This is the model class for table "base_products".
*
* @property integer $id
* @property integer $product_categoryID
* @property integer $product_sub_categoryID
* @property integer $product_directionsID
* @property integer $product_ghsID
* @property integer $product_call_outID
* @property string $product_formula
* @property string $product_image
* @property string $product_name
* @property string $product_sub_name
* @property string $product_spanish
* @property string $product_bullets
* @property string $product_description
* @property integer $product_alt_label
* @property integer $product_green_seal
* @property integer $product_dfe
* @property string $call_out_object_style
*
* @property Category $productCategory
* @property Directions $productDirections
* @property SubCategory $productSubCategory
* @property CallOut $productCallOut
* @property Ghs $productGhs
* @property CustomerProducts[] $customerProducts
*/
class BaseProducts extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'base_products';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['product_categoryID', 'product_formula', 'product_image', 'product_name', 'product_alt_label', 'product_green_seal', 'product_dfe'], 'required'],
[['product_categoryID', 'product_sub_categoryID', 'product_directionsID', 'product_ghsID', 'product_call_outID', 'product_alt_label', 'product_green_seal', 'product_dfe'], 'integer'],
[['product_bullets', 'product_description'], 'string'],
[['product_formula', 'call_out_object_style'], 'string', 'max' => 32],
[['product_image', 'product_name', 'product_sub_name', 'product_spanish'], 'string', 'max' => 255],
[['product_categoryID'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['product_categoryID' => 'id']],
[['product_directionsID'], 'exist', 'skipOnError' => true, 'targetClass' => Directions::className(), 'targetAttribute' => ['product_directionsID' => 'id']],
[['product_sub_categoryID'], 'exist', 'skipOnError' => true, 'targetClass' => SubCategory::className(), 'targetAttribute' => ['product_sub_categoryID' => 'id']],
[['product_call_outID'], 'exist', 'skipOnError' => true, 'targetClass' => CallOut::className(), 'targetAttribute' => ['product_call_outID' => 'id']],
[['product_ghsID'], 'exist', 'skipOnError' => true, 'targetClass' => Ghs::className(), 'targetAttribute' => ['product_ghsID' => 'id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'product_categoryID' => 'Category ID Number',
'product_sub_categoryID' => 'Sub Category ID Number',
'product_directionsID' => 'Directions ID Number',
'product_ghsID' => 'GHS ID Number',
'product_call_outID' => 'Call Out ID Number',
'product_formula' => 'Formula',
'product_image' => 'Image File',
'product_name' => 'Name',
'product_sub_name' => 'Sub Name',
'product_spanish' => 'Spanish Translation',
'product_bullets' => 'Bullets',
'product_description' => 'Description',
'product_alt_label' => 'Alternate Label (13.5 x 4.5)',
'product_green_seal' => 'Green Seal',
'product_dfe' => 'Safer Choice',
'call_out_object_style' => 'Call Out Object Style',
];
}
public function beforeSave($insert){
if (!parent::beforeSave($insert))
return false;
//Insert directions and GHS then retrieve the ids for new base products
$directions = new Directions();
$ghs= new Ghs();
if ($insert) {
//Directions
$directions->product_directions=[b][i]FORM VALUE GOES HERE[/i][/b];
$directions->save(); //to avoid foreign key check failure
$this->product_directionsID = Yii::$app->db->getLastInsertID();
} else {
//updating record code here
//$directions->id = $this->product_directionsID;
$directions->product_directions = b][i]FORM VALUE GOES HERE[/i][/b];
}
return true;
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProductCategory()
{
return $this->hasOne(Category::className(), ['id' => 'product_categoryID']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProductDirections()
{
return $this->hasOne(Directions::className(), ['id' => 'product_directionsID']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProductSubCategory()
{
return $this->hasOne(SubCategory::className(), ['id' => 'product_sub_categoryID']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProductCallOut()
{
return $this->hasOne(CallOut::className(), ['id' => 'product_call_outID']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProductGhs()
{
return $this->hasOne(Ghs::className(), ['id' => 'product_ghsID']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCustomerProducts()
{
return $this->hasMany(CustomerProducts::className(), ['customer_product_base_productID' => 'id']);
}
}