我可能会错过一些东西,但我自己也无法解决问题。
我正在获得白屏(存储/日志中没有日志,Apache日志中没有200个代码)。我认为返回View :: make()不会传递视图字符串。
在routes.php中
Route::get('/home', array('as' => 'home', 'uses' => 'HomeController@index'))->before('guest');
在filters.php中
Route::filter('guest', function(){
if (Auth::check() === true) {
return Redirect::route('dashboard')->with('flash_notice', 'You are already logged in!');
}});
在HomeController.php
中class HomeController extends BaseController {
public function index()
{
return View::make('login');
}}
在views / login.blade.php
中@extends('layouts.login')
在views / layouts / login.blade.php中只是HTML
一旦我改变了返回View :: make('login');回显View :: make('login');我得到了渲染视图。
我之前安装了相同的代码库并且它有效(是的,它也是Laravel 4),所以我想知道这与新的库版本有某种关系。
感谢您的帮助。
答案 0 :(得分:1)
在views / layouts文件夹中创建一个主文件base.blade.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<title>Signin</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<style>
body {
background-color: #EEEEEE;
padding-bottom: 40px;
padding-top: 40px;
}
.form-signin {
margin: 0 auto;
max-width: 330px;
padding: 15px;
}
.form-signin .form-signin-heading, .form-signin .checkbox {
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
@section('maincontent')
@show
</div>
</body>
</html>
然后在你的login.blade.php:
@extends('layouts.base')
@section('maincontent')
<form class="form-signin" action="/login" method="POST" >
@if ($errors->first('login'))
<div class="alert alert-danger" >
{{$errors->first('login')}}
</div>
@endif
@if ($errors->first('password'))
<div class="alert alert-danger" >
{{$errors->first('password')}}
</div>
@endif
@if(Session::has('flash_notice'))
<div class="alert alert-danger" >
{{Session::get('flash_notice')}}
</div>
@endif
@if(Session::has('flash_success'))
<div class="alert alert-success" >
{{Session::get('flash_success')}}
</div>
@endif
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" class="form-control" placeholder="Login" name="login" autofocus>
<input type="password" class="form-control" placeholder="Password" name="password" >
<label class="checkbox"></label>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
@stop
答案 1 :(得分:0)
更改路线:
Route::get('home', array('as' => 'home', 'before' => 'guest', 'uses' => 'HomeController@index'));