MongoDB と FuelPHP を使用しています。MongoDB に正常に接続し、データを抽出できます。ビューにデータを挿入する方法を理解するために、すでに 3 日間を費やしました。私の見解は次のとおりです。
<body>
<div class="middle">
<p><?php if (isset($_id)){echo $_id;} ?></p>
<p><?php if (isset($first_name)){echo $first_name;} ?></p>
<p><?php if (isset($last_name)){echo $last_name;} ?></p>
</div>
</body>
私のコントローラーは:
class Controller_Home extends Controller {
public function action_index()
{
$data['css'] = Asset::css(array('reset.css','main.css'));
$results = Model_Home::get_results();
//I thought all I have to do is this foreach loop and it would work
foreach($results as $row => $val){
$data = $val;
}
$this->response->body = View::factory('home/index', $data);
}
}
私の var_dump() は次のとおりです。
object(stdClass)#10 (2) {
[0]=>
array(5) {
["_id"]=>
object(MongoId)#13 (1) {
["$id"]=>
string(24) "4ef82a27b238f02ed9000000"
}
["cms"]=>
array(1) {
[0]=>
string(8) "Druapl_1"
}
["first_name"]=>
string(6) "Name_1"
["last_name"]=>
string(10) "Lst_Name_1"
["skills"]=>
array(3) {
[0]=>
string(6) "html_1"
[1]=>
string(5) "css_1"
[2]=>
string(8) "jQuery_1"
}
}
[1]=>
array(5) {
["_id"]=>
object(MongoId)#14 (1) {
["$id"]=>
string(24) "4ef81a0dcf163c7da3e5c964"
}
["cms"]=>
array(1) {
[0]=>
string(8) "Druapl_2"
}
["first_name"]=>
string(6) "Name_2"
["last_name"]=>
string(10) "Lst_Name_2"
["skills"]=>
array(3) {
[0]=>
string(6) "html_2"
[1]=>
string(5) "css_2"
[2]=>
string(8) "jQuery_2"
}
}
}
現在は機能していますが、何らかの理由でビューに最初のアイテムしか表示されません。
4ef81a0dcf163c7da3e5c964
Name_2
Lst_Name_2
html_2
css_2
jQuery_2
Druapl_2
私の古い宿敵である foreach ループで何かがひどく間違っていると思います... 助けてください。ありがとうございました。