【发布时间】:2014-12-17 20:17:57
【问题描述】:
在我的路线中,我将此路线定义为:
// app/routes.php
Route::resource('CharacterController');
控制器中对应的方法是:
// app/controllers/CharacterController.php
public function index(){
$characters = Character::all();
$houses = House::all();
return View::make('characters.index')->with(array('characters'=>$characters, 'houses' => $houses));
}
最后,在视图中:
// app/views/characters/index.blade.php
#this fires an error:
{{ $houses[$characters->house_id]->name }}
# at the same time this gives correct result:
{{ $houses[1]->name }}
# and this IS equal to 1:
{{ $characters->house_id }}
【问题讨论】:
-
这是因为 $characters->house_id 是一个字符串吗?试试 intval() 看看会发生什么。
-
@Joe 谢谢,已经尝试过了,但不幸的是给出了相同的未定义偏移错误