Answer the question
In order to leave comments, you need to log in
How to pass the parent id of the added object (child element) to the session?
Hello everybody! There is a function to add an object to the session, the code is given below, the code is working. Please tell me the following, how to do that if I add an object of the "Monitor" type to the session, then in the session 'contract_id' receives a parameter from the parent element (User's Workplace), in this case the number 6? Adding 'contract_id' to the session comes from the associated table.
public function addToDoc($accept){
$_SESSION['form'][$accept->id] = [
'equipment' => $accept->equipment,
'type_id' => $accept->type_id,
'contract_id' => $accept->type->contract_id,
'shk_osk' => $accept->shk_osk,
'serial_number' => $accept->serial_number,
];
}
Таблица accept
public function getType(){
return $this->hasOne(Type::className(), ['id' => 'type_id']);
}
Таблица type
public function getAccepts(){
return $this->hasMany(Accept::className(), ['type_id' => 'id']);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question