getting unknown property

Unknown Property – yii\base\UnknownPropertyException

Getting unknown property: app\models\Order::semenid

This points to the order\view page gridview as follows




<?php //views/order/view

		GridView::widget([

        'dataProvider' => $dataProvider,

        //'filterModel' => $searchModel,

        'columns' => [

            ['class' => 'yii\grid\SerialColumn'],

            'orderid',

            'semenid',

            'quantity',

            ['class' => 'yii\grid\ActionColumn'],

        ],

    ]); /**/?>



Lastly what should be the array parameters in search/orderController/actionView below since orderid is given as $id




$dataProvider = $searchModel->search($id); //is this right



DB Schema

CREATE TABLE order (

orderid int(8) NOT NULL AUTO_INCREMENT,

user_id int(11) NOT NULL,

orderdate date DEFAULT NULL COMMENT ‘date of receiving order’,

vet_id int(11) NOT NULL COMMENT ‘vet allocated’,

servingdate date DEFAULT NULL COMMENT ‘date for serving the cow’,

PRIMARY KEY (orderid)

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

/*Data for the table order */

insert into order(orderid,user_id,orderdate,vet_id,servingdate) values (2,3,‘2015-10-29’,8,‘2015-11-28’),(3,4,‘2015-12-31’,9,‘2016-01-05’);

CREATE TABLE orderdetails (

orderdetailsid int(8) NOT NULL AUTO_INCREMENT,

orderid int(8) NOT NULL,

semenid int(8) NOT NULL,

quantity int(3) NOT NULL,

PRIMARY KEY (orderdetailsid),

KEY order_id (orderid),

CONSTRAINT order_id FOREIGN KEY (orderid) REFERENCES order (orderid)

) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

/*Data for the table orderdetails */

insert into orderdetails(orderdetailsid,orderid,semenid,quantity) values (1,2,1,2),(2,2,2,1),(3,3,3,2),(4,3,4,1);

master-detail scenario

Got two tables and models, order and orderdetails (master & detail respectively).

In the order model view, i intend to display a gridview of the corresponding orderdetails below the master details. Problem is somehow the join is dysfunctional and generates error purporting to not recognize the detail fields.




//OrderController

    public function actionView($id)

    {

        $searchModel = new OrderSearch();

		$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

		return $this->render('view', [

		'model' => $this->findModel($id), 

		'searchModel' => $searchModel,

		'dataProvider' => $dataProvider,

		]);  

    }


//orderSearch

    public function rules()

    {

        return [

            [['orderid', 'user_id', 'vet_id'], 'integer'],

            //[['orderdate', 'servingdate', 'semenid'], 'safe'],

        ];

    }


    /**

     * @inheritdoc

     */

    public function scenarios()

    {

        // bypass scenarios() implementation in the parent class

        return Model::scenarios();

    }


    /**

     * Creates data provider instance with search query applied

     *

     * @param array $params

     *

     * @return ActiveDataProvider

     */

    public function search($params)

    {

        $query = Order::find();


        $dataProvider = new ActiveDataProvider([

            'query' => $query,

        ]);


		/**

		 * Setup your sorting attributes

		 * Note: This is setup before the $this->load($params) 

		 * statement below

		 */

		$dataProvider->setSort([

			'attributes' => [

				'orderid',

				'user_id',

				'orderdate',

				'semenid',

				'servingdate',

				'vet_id',

				'farmer' => [

					'asc' => ['firstname' => SORT_ASC, 'lastname' => SORT_ASC],

					'desc' => ['firstname' => SORT_DESC, 'lastname' => SORT_DESC],

					'label' => 'Full Name',

					'default' => SORT_ASC

				],

			]

		]);		




        $this->load($params);


        if (!($this->load($params) && $this->validate())) {

            // uncomment the following line if you do not want to return any records when validation fails

            // $query->where('0=1');

            $query->joinWith(['orderdetails']);

			return $dataProvider;




			$this->addCondition($query, 'orderid');

			$this->addCondition($query, 'orderdate', true);

			$this->addCondition($query, 'servingdate', true);

			$this->addCondition($query, 'vet_id', true);

			$this->addCondition($query, 'semenid', true);

			$this->addCondition($query, 'user_id');

        }


        $query->andFilterWhere([

            'orderid' => $this->orderid,

            'user_id' => $this->user_id,

            'orderdate' => $this->orderdate,

			'semenid' => $this->semenid,

            'vet_id' => $this->vet_id,

            'servingdate' => $this->servingdate,

        ]);

		print_r($query->createCommand()->getRawSql());

        return $dataProvider;

    }


//ordermodel

class Order extends \yii\db\ActiveRecord

{

    /**


    /**

     * @return \yii\db\ActiveQuery

     */

    public function getOrderdetails()

    {

        return $this->hasMany(Orderdetails::className(), ['orderid' => 'orderid']);

    }

}




dude, pls use <code></code>

Thanks for advice. done.

hi,

[color=#880000]//[[‘orderdate’, ‘servingdate’, ‘semenid’], ‘safe’],[/color]

why is the last three fields commented out?