我试图将表名传递给我的模型,因为模型在两个表上运行,但具有相同的方法。在模型中设置表名称?
我这样做,像这样:
$this->model = new Emotions(array('section' => 'red'));
和模型我设置表所示:
public function __construct($attributes = array(), $exists = false){
parent::__construct($attributes, $exists);
$this->table = $attributes['section'];
}
但我得到的错误:
Undefined index: section
任何想法哪里我错了?
奇怪。我测试过了,你的代码工作正常。你有没有试过传递一个非关联数组来查看是否有效?传递数组('red')并查看是否可以将它作为属性[0]访问。使用不同的字符集有什么改变吗? – tliokos
否 - 未定义偏移量:0 – panthro
问题是,我可以var_dump出$ attributes ['section']并给出正确的输出,只有当我尝试设置$ table时才会失败。 – panthro