使用 Laravel API ,我尝试从数据库中基本选择数据。
我对从API提取数据到html页面有疑问。
我的控制器:
class ContentController extends Controller
{
//
public function first_data() {
$table_slider = DB::select('SELECT content_id,link,file,slider_sorting,content_pages FROM content_structure as cs LEFT JOIN (SELECT cid,file FROM content_upload_assets) cua ON cs.content_id = cua.cid WHERE content_pages = ? AND cs.status = ? ORDER BY content_id DESC ',[
'Slider',
'Active'
]);
return View('fetch_first_data',['jsondata' => json_encode($table_slider)]);
}
public function fetch_first_data() {
return View('fetch_first_data');
}
}
查看:fetch_first_data.blade.php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
{{$jsondata}}
</body>
</html>
在我的web.php路由器中:
Route::get('/fetch_first_data','ContentController@fetch_first_data');
在我的api.php路由器中:
Route::get('first_data','ContentController@first_data');
问题:
答案 0 :(得分:3)
public function first_data() {
$table_slider = DB::select('SELECT content_id,link,file,slider_sorting,content_pages FROM content_structure as cs LEFT JOIN (SELECT cid,file FROM content_upload_assets) cua ON cs.content_id = cua.cid WHERE content_pages = ? AND cs.status = ? ORDER BY content_id DESC ',[
'Slider',
'Active'
]);
return View('fetch_first_data',['jsondata' => json_encode($table_slider)]);
}
然后在刀片文件中打印 {{$ jsondata}} 。