Related Data in _form for Updating

I need to get my model’s related data


$model->productDirections->product_directions

into _form from gridview for updating


<?= $form->field($model, 'fieldName')->hint('Hint Here')->textarea(['rows' => 6]) ?>

I have tried using


productDirections.product_name

for fieldName but receive an Unknown Prperty Exception error and using


$model->productDirections->product_directions

throws an Attribute name must contain word characters only.

What is the proper why to set this up?

Model


<?php


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_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 CustomerProducts[] $customerProducts

 * @property Ghs[] $ghs

 */

class BaseProducts extends \yii\db\ActiveRecord

{

    /**

     * @inheritdoc

     */

    public static function tableName()

    {

        return 'base_products';

    }


    /**

     * @inheritdoc

     */

    public function rules()

    {

        return [

            //, 'product_sub_name', 'product_spanish', 'product_bullets', 'product_description', 'call_out_object_style'

            [['product_categoryID', 'product_directionsID', 'product_formula', 'product_image', 'product_name'], 'required'],

            [['product_categoryID', 'product_sub_categoryID', 'product_directionsID', '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']],

        ];

    }


    /**

     * @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_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',

        ];

    }


    /**

     * @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 getCustomerProducts()

    {

        return $this->hasMany(CustomerProducts::className(), ['customer_product_base_productID' => 'id']);

    }


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getGhs()

    {

        return $this->hasMany(Ghs::className(), ['ghs_productID' => 'id']);

    }

}



http://www.yiiframework.com/doc-2.0/guide-input-multiple-models.html

This is for using two models. Is there no way to use related data?

Seems like this will bring in related data


 $profile = Profile::findOne($user->profile_id);

Got it working. Thanks for the link.