如何在yii2中从另一个模型或控制器的一个视图窗体中获取值?
我需要你的帮助。我有查看表单search.php(modules/user/default/search)。我需要从该搜索表单获取用户的电子邮件($email),并将其传输到ContactForm(模块/main/models/ContactForm)或ContactController(模块/main/Controller/ContactController)。我怎样才能到达这里 这是我的搜索表上的cod如何在yii2中从另一个模型或控制器的一个视图窗体中获取值?,yii2,Yii2,我需要你的帮助。我有查看表单search.php(modules/user/default/search)。我需要从该搜索表单获取用户的电子邮件($email),并将其传输到ContactForm(模块/main/models/ContactForm)或ContactController(模块/main/Controller/ContactController)。我怎样才能到达这里 这是我的搜索表上的cod <?php $this->title = Yii::t('app', 'TI
<?php
$this->title = Yii::t('app', 'TITLE_SEARCH');
?>
<?php use yii\helpers\Html; ?><br>
<div class="text-left"><a href="<?='/taxi/web/user/default/index'?>" class="btn" style="background-color: honeydew" >Назад к Поиску</a></div>
<br><br>
<?php if (!$result) { ?>
<p>Ничего не найдено</p>
<?php } else { ?>
<?php foreach ($result as $one){
$from = $one -> from;
$to = $one -> to;
$age = $one -> age;
$username = $one -> username;
$usersurname = $one -> usersurname;
$data = $one -> data;
$time = $one -> time;
$price = $one -> price;
$place = $one -> place;
$email = $one -> email;
$id = $one -> id;
?>
<div class="container" style=" border-radius: 5px">
<div class="col-xs-1"></div>
<div class="col-xs-10" style="background-color:mintcream; border-radius: 5px">
<div class="col-xs-3" style="">
<div class="row">
<div class="col-xs-12 text-center">
<h4><?=$username?> <?=$usersurname?></h4>
<p><?= Yii::t('app', 'TITLE_AGE')?>:<?= $age ?></p>
<div class="col-xs-12 text-right">
<a class="btn siteColor2" href='<?=Yii::$app->urlManager->createUrl(["user/profile/user"])?>'> <?=Yii::t('app', 'BUTTON_DRIVER_PAGE'); ?></a>
</div>
</div>
</div><br>
</div>
...
С型触媒
<?php
namespace app\modules\main\models;
use Yii;
use yii\base\Model;
/**
* ContactForm is the model behind the contact form.
*/
class ContactForm extends Model
{
public $name;
public $email;
public $subject;
public $body;
public $verifyCode;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// name, email, subject and body are required
[['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address
['email', 'email'],
// verifyCode needs to be entered correctly
['verifyCode', 'captcha', 'captchaAction' => '/main/contact/captcha'],
];
}
/**
* @return array customized attribute labels
*/
public function attributeLabels()
{
return [
'verifyCode' => Yii::t('app', 'USER_VERIFYCODE'),
'name' => Yii::t('app', 'USER_USERNAME'),
'email' => Yii::t('app', 'USER_EMAIL'),
'subject' => Yii::t('app', 'USER_SUBJECT'),
'body' => Yii::t('app', 'USER_BODY'),
];
}
/**
* Sends an email to the specified email address using the information collected by this model.
* @param string $email the target email address
* @return boolean whether the model passes validation
*/
public function contact($email)
{
if ($this->validate()) {
Yii::$app->mailer->compose()
->setTo($email)
->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])
->setReplyTo([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
return true;
} else {
return false;
}
}
}
您好,您可以尝试此会话:
在您的视图中设置:
\Yii::$app->session->set('email', 'emil@example.com');
以及您要检索的位置:
\Yii::$app->session->get('email');
或使用闪光灯:
Yii::$app->session->setFlash('email', 'emil@example.com');
echo Yii::$app->session->getFlash('email');
在会话中保存电子邮件并到达那里。@Muhammad Shahzad举一些例子,我会接受答案
\Yii::$app->session->get('email');
Yii::$app->session->setFlash('email', 'emil@example.com');
echo Yii::$app->session->getFlash('email');