php - 如何解决 compact() 函数中的未定义变量错误?
问题描述
我想发送包含一些信息的电子邮件。这就是我compact()
在函数中使用函数的原因view()
。但我得到一个错误“未定义的变量”:
public $message_to_send="";
public $first_name_to_send="";
public function __construct($first_name,$message) {
$this->message_to_send=$message;
$this->first_name_to_send=$first_name;
}
public function build(){
return $this->view('email/contactmessageemail',compact('message_to_send','first_name_to_send'));
}
错误信息是:
compact():未定义变量:message_to_send
解决方案
尝试将其编辑为
view('email.contactmessageemail',[
'message_to_send' => $this->message_to_send,
'first_name_to_send' => $this->first_name_to_send
]);
compact
在您的情况下不起作用,因为您要传入的变量不是在方法范围内本地定义的,它被声明为公共属性
推荐阅读
- ruby - 在 post_install Podfile 挂钩中删除链接的 Pods_framework
- tensorflow - Try/Except 不适用于 tflearn。请
- linux - bash 脚本,获取子目录的名称
- r - 想要将前一个日期行字段增加另一列中的值并且滞后不起作用
- python - 我无法使用 Python 和 Django 在网页上显示数据库中的数据
- python - 如何从课堂外访问课程列表?
- python - 如何检查某物是否在列表中的多个项目范围内?
- amazon-web-services - 在 auth 配置中找不到 Pod 执行角色或没有所有必需的权限。我该如何调试?
- r - 计算因素的出现并将它们总结在R中的行和列中
- php - 如何在管理员批量订单操作中跳过具有特定元数据的订单