关注博主,每天分享项目实战经验
1.首先找到页面的公共部分,放在layouts这个目录下的home.blade.php
2.设置内容区域
@yield('content')
3.在其他页面使用模板引擎,先继承,然后在使用section即可
@extends('layouts.home')
@section('content')
<div class="login">
<div class="container">
<form action="" method="post">
<div class="col-md-6 login-do1 animated wow fadeInLeft" data-wow-delay=".5s">
<div class="login-mail">
<input type="text" name="email" placeholder="Email" required="">
<i class="glyphicon glyphicon-envelope"></i>
</div>
<div class="login-mail">
<input type="password" name="password" placeholder="Password" required="">
<i class="glyphicon glyphicon-lock"></i>
</div>
<div class="login-mail">
<input type="password" name="repeate" placeholder="Repeated password" required="">
<i class="glyphicon glyphicon-lock"></i>
</div>
<a class="news-letter" href="#">
<label class="checkbox1"><input type="checkbox" name="checkbox" ><i> </i>I agree with the terms</label>
</a>
</div>
<div class="col-md-6 login-do animated wow fadeInRight" data-wow-delay=".5s">
<label class="hvr-sweep-to-top login-sub">
<input type="submit" value="Submit">
</label>
<p>Already register</p>
<a href="login.html" class="hvr-sweep-to-top">Login</a>
</div>
<div class="clearfix"> </div>
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
</form>
</div>
</div>
@endsection
4.在这里其实还有一个问题,那就是文件的title这个值,这个值我们需要怎么做呢!其实也很简单
将下边的这代码放置在一个公共的控制器,其他的控制器继承这个控制器,在每次加载页面的时候,调用这个方法即可
名为HomeController.php
public function set_page_info($title, $keywords, $description, $showNav, $css=array(), $js=array()){
return array(
'page_title' => $title,
'page_keywords' => $keywords,
'page_description' => $description,
);
IndexController.php
/*
author:咔咔
address:陕西西安
wechat:fangkangfk
*/
class IndexController extends HomeController
{
/**
* @return $this
*/
public function index(Request $request){
//设置页面信息
$data = $this->set_page_info('京西商城','京西','京西');
}
}