很抱歉发布了我未能找到的简单问题:
public function show(){
function display(){
$q = DB::table('posts')->get();
return $q;
}
$m = new Post;
$data = $m->display();
foreach($data as $row)
{
?>
<tr>
<td><?= $row->id ?></td>
<td><?= $row->name ?></td>
<td><?= $row->description ?></td>
</tr>
<?
}
exit();
}
主要是我在控制器中面对foreach循环的问题,我试图在视图中显示ajax请求。
答案 0 :(得分:1)
public function show() {
function display() {
$q = DB::table('posts')->get();
return $q;
}
$m = new Post;
$data = $m->display();
foreach ($data as $row) {
?>
<tr>
<td><?= $row->id ?></td>
<td><?= $row->name ?></td>
<td><?= $row->description ?></td>
</tr>
<?php
}
exit();
}