批改狀態(tài):合格
老師批語(yǔ):寫(xiě)得很認(rèn)真, 命令創(chuàng)建效率和正確率要優(yōu)于手工
1、分別創(chuàng)建控制器、視圖、路由文件
<?php namespace App\Http\Controllers\admin; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class Home extends Controller { public function index(){ $data['title'] = '2019大閱兵'; return view('admin/home/index',$data); } } ?>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
<?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return view('welcome'); }); Route::get('/304525', function () { // 讀取數(shù)據(jù) $article = array('title'=>'2019國(guó)慶大閱兵','detail'=>'獎(jiǎng)勵(lì)上級(jí)阿薩德老費(fèi)勁啊勝利大街愛(ài)上了就發(fā)了房間里睡大覺(jué)','auth'=>array('username'=>'admin','age'=>18)); return view('article/detail',$article); }); Route::get('/home','home@index'); Route::get('/article/detail',function (){ return ('<div style="margin: 10px auto;text-align:center; font-weight: bold;color: red;">新聞列表</div>'); }); Route::get('/admin/home/index','admin\Home@index'); ?>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div style="text-align: center;">{{$title}}</div> </body> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
2、在控制器中模擬數(shù)據(jù),并把數(shù)據(jù)渲染到視圖中
<?php namespace App\Http\Controllers\admin; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class Home extends Controller { public function index(){ $data['navs'] = array(array('title'=>'企業(yè)logo','url'=>'/'),array('title'=>'新聞資訊','url'=>'/'),array('title'=>'最新產(chǎn)品','url'=>'/')); return view('admin/home/index',$data); } } ?>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
3、使用@include將頁(yè)面的header部分放到public/header.php中
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>企業(yè)站</title> <style> .header{background-color: #000;width: 100%;height: 50px; text-align: center;} .header a{line-height: 50px;color: #fff;margin: 0 20px;text-decoration: none;} .nav-left{width: 200px;height: 500px;background-color: red;float:left;} .news{width: 300px;height: 500px;background-color: green;float:left;} </style> </head> <body> {{--header導(dǎo)航--}} @include('admin/public/header') {{--left導(dǎo)航--}} <div class="nav-left"></div> {{--right 文字列表--}} <div class="news"></div> </body> </html>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
<?php namespace App\Http\Controllers\admin; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class Home extends Controller { public function index(){ $data['navs'] = array(array('title'=>'企業(yè)logo','url'=>'/'),array('title'=>'新聞資訊','url'=>'/'),array('title'=>'最新產(chǎn)品','url'=>'/')); return view('admin/home/index',$data); } } ?>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
<div class="header"> @foreach($navs as $nav){ <a href="{{$nav['url']}}">{{$nav['title']}}</a> } @endforeach </div>
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)