我刚开始旅行,我被卡住了。
我的问题是我想要2节(导航,内容)有动态数据
下面是一些代码主要叶片
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Portfolio</title>
</head>
<body>
<div class="navigation">
@yield('menu')
</div>
<div class="content">
@yield('content')
</div>
</body>
</html>
组合叶片
@extends('main')
@section('content')
@foreach($data as $portfolio)
<a href="portfolio/{!!$portfolio->portfolio_url!!}"><img src='{{ URL::asset("images/$portfolio->picture.jpg") }}'/></a>
@endforeach
@stop
和我的导航条
@extends('main')
@section('menu')
@foreach($menuknoppen as $menuknop)
<a href='{{ URL::to("$menuknop->menu_url") }}'>{{$menuknop->menutitle}}</a>
@endforeach
@stop
组合刀片有一个控制器,但菜单刀片也有一个控制器
Edit1:
问题是导航栏没有显示即使我添加了静态文本
Edit2:
我的控制器我的投资组合控制器
/**
* Show the profile for the given user.
*
* @param int $id
* @return Response
*/
public function index(){
//here comes a whole list with what i've done
$results = DB::table('projects')->get();
//return $results;
$data = array();
foreach ($results as $key => $result) {
$data[] = $result;
}
return view('portfolio.portfolio')->with('data', $data);
}
public function getProject($portfolio_url){
//this gets the project thats clicked
$results = DB::select('select * from projects where portfolio_url = ?', array($portfolio_url));
return view('portfolio.single')->with('data', $results['0']);
}
}
我的导航控制器class menuController extends Controller {
/**
* Show the profile for the given user.
*
* @param int $id
* @return Response
*/
// public function __construct($table){
// $results = DB::table($table)->get();
// return view('menu')->with('menuknoppen', $results);
// }
public function index(){
$results = DB::table('navigation')->get();
return view('menu')->with('menuknoppen', $results);
}
}
你的主刀片应该是:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Portfolio</title>
</head>
<body>
<div class="navigation">
@include('menu');
</div>
<div class="content">
@yield('content')
</div>
</body>
</html>
你的作品集应该是:
@extends('main')
@section('content')
@foreach($data as $portfolio)
<a href="portfolio/{!!$portfolio->portfolio_url!!}"><img src='{{ URL::asset("images/$portfolio->picture.jpg") }}'/></a>
@endforeach
@stop
导航栏应该是:
//Don't use extends here
@foreach($menuknoppen as $menuknop)
<a href='{{ URL::to("$menuknop->menu_url") }}'>{{$menuknop->menutitle}}</a>
@endforeach
传递多个数据
public function index()
{
$data = //data code;
$results = // results code
return view(portfolio.portfolio, compact('data', 'results'));
}
您已经混合了@yield, @include和@extend的概念
@yield为您提供了一个替换的位置,所以当您在其他视图中调用@extend时,您可以重用视图中的模板,您可以扩展和替换@yield
部分@include意味着这部分代码总是被它所定义的视图所替换
所以当你在设计一个网页时,你需要确定什么是"总是调用"(使用@include),什么是可以替换的(使用@yield)
作为对aldrin27工作代码的辅助解释,我希望这能让你对刀片模板有更清晰的认识,它太棒了!: D