【发布时间】:2020-07-29 10:33:39
【问题描述】:
这是我整理的模型的构造函数;
public function __construct($attributes = array()) {
parent::__construct($attributes);
var_dump($attributes);
exit;
}
var_dump 输出是;
array(1) { ["table"]=> string(14) "participants_2" }
但是当我尝试这个时;
public function __construct($attributes = array()) {
parent::__construct($attributes);
$this->table = $attributes["table"];
}
我明白了;
ErrorException in Participant.php:
Undefined index: table
我将$this 行放在parent::__construct 行之前还是之后都没有关系。这怎么可能是一个未定义的索引?我已经定义了,对吧?
可能是 Laravel 的问题?
【问题讨论】:
-
我唯一能想到的就是不同的上下文...尝试一下 var_dumping 和设置。
-
你是怎么解决的?
标签: php laravel laravel-5.2