Laravel控制器和视图

控制器,rawSQL,Model

controller.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use DB; class MyController extends Controller
{
public function hello()
{ $articles = DB::select('select * from posts'); return View('myview',['d1'=>$articles]);
}
}

这里控制器给blade页面传递了一个数组,这个数组是直接通过数据库查询来的。

*.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">{{ count($d1) }}</div> <div class="panel-body">
this is my view!
</div> @for($i = 0; $i < count($d1); $i++)
<p>{{ $d1[$i]->content }}</p>
@endfor </div>
</div>
</div>
</div>
@endsection
上一篇:Maven中settings.xml的配置项说明精讲


下一篇:【.net 深呼吸】在运行阶段修改应用配置文件