Answer the question
In order to leave comments, you need to log in
How to pass variable to layouts/main.php?
There is a SiteController function in it
public function index(){
$contactForm = new FooterForm();
if ($contactForm->load(Yii::$app->request->post()) && $contactForm->validate()) {
if ($contactForm->sendEmail()) {
Yii::$app->session->setFlash('success', 'Спасибо - мы свяжемся с Вами в ближайшее время');
} else {
Yii::$app->session->setFlash('error', 'Произошла ошибка при отправке сообщения.');
}
return $this->refresh();
}
return [
'contactForm' => $contactForm,
];
}
Answer the question
In order to leave comments, you need to log in
I think $contactForm is a local variable that will be destroyed when the function exits. To pass a reference to new FooterForm() assign it to a global variable
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question