Laravel 4 - 无法显示页面

时间:2015-12-26 05:34:39

标签: laravel laravel-4 laravel-5

我尝试重定向到“登录”'页面,但页面显示为空白。请在相应页面上查看以下编码:

在routes.php上:

Route::resource('users','UserController'); Route::get('/users/login', array('as' => 'users.login', 'uses' => 'UserController@getLogin'));

On UserController.php:

<?php

class UserController extends \BaseController {

/**
 * Display a listing of the resource.
 *
 * @return Response
 */
public function index()
{
    $users = User::paginate(10);
    return View::make('users.index', compact('users'), array('users' => $users));

}
public function getLogin() {
return View::make('users.login');
$this->layout->content = View::make('users.login');
 }
}

我在&#34; app \ views \ users&#34;下创建了两个视图文件。位置:

  1. user.blade.php(主刀片文件)
  2. login.blade.php(
  3. user.blade文件的内容如下:

    <!doctype html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>@yield('title')</title>
        <meta name="description" content="@yield('description')">
        <link href="//netdna.bootstrapcdn.com/twitter-bootstrap
        /2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
        <style>
            table form { margin-bottom: 0; }
            form ul { margin-left: 0; list-style: none; }
            .error { color: red; font-style: italic; }
            body { padding-top: 20px; }
            /* Pagination styling */ 
    
            .pagination { display: inline-block; padding-right: 0; margin: 20px 0; border-radius: 4px; float: right; } .pagination>li { display: inline } .pagination>li>a, .pagination>li>span { position: relative; float: right; padding: 6px 12px; line-height: 1.428571429; text-decoration: none; color: #333333; background-color: #fff; border: 1px solid #e4e4e4; } .pagination>li:first-child>a, .pagination>li:first-child>span { margin-right: 0; border-bottom-right-radius: 4px; border-top-right-radius: 4px } .pagination>li:last-child>a, .pagination>li:last-child>span { border-bottom-left-radius: 4px; border-top-left-radius: 4px } .pagination>li>a:hover, .pagination>li>span:hover, .pagination>li>a:focus, .pagination>li>span:focus { color: #fff; background-color: #ffae12; border-color: #ffae12 } .pagination>.active>a, .pagination>.active>span, 
            .pagination>.active>a:hover, .pagination>.active>span:hover, .pagination>.active>a:focus, .pagination>.active>span:focus { z-index: 2; color: #fff; background-color: #F2541B; border-color: #F2541B; cursor: default } .pagination>.disabled>span, .pagination>.disabled>span:hover, .pagination>.disabled>span:focus, .pagination>.disabled>a, .pagination>.disabled>a:hover, .pagination>.disabled>a:focus { color: #777; background-color: #fff; border-color: #ddd; cursor: not-allowed } .pagination-lg>li>a, .pagination-lg>li>span { padding: 10px 16px; font-size: 18px } .pagination-lg>li:first-child>a, .pagination-lg>li:first-child>span { border-bottom-right-radius: 6px; border-top-right-radius: 6px } .pagination-lg>li:last-child>a, .pagination-lg>li:last-child>span { border-bottom-left-radius: 6px; border-top-left-radius: 6px } .pagination-sm>li>a, .pagination-sm>li>span { 
            padding: 5px 10px; font-size: 12px } 
            .pagination-sm>li:first-child>a, .pagination-sm>li:first-child>span { border-bottom-right-radius: 3px; border-top-rightt-radius: 3px } .pagination-sm>li:last-child>a, .pagination-sm>li:last-child>span { border-bottom-left-radius: 3px; border-top-left-radius: 3px }
    
    
    
        </style>
    </head>
    
    <body>
    
        <div class="container">
            @if (Session::has('message'))
                <div class="flash alert">
                    <p>{{ Session::get('message') }}</p>
                </div>
            @endif
    
            @yield('main')
        </div>
    
    </body>
    

    login.blade文件的内容如下:

    @extends('users.user') 
    
    @section('main')
    
    <h1>Login</h1>
    
    {{ Form::open(array('route' => 'users.getlogin')) }}
    <ul>
    
    
        <li>
            {{ Form::label('username', 'Username:') }}
            {{ Form::text('username') }}
        </li>
    
        <li>
            {{ Form::label('password', 'Password:') }}
            {{ Form::password('password') }}
        </li>
    
    
        <li>
            {{ Form::submit('Submit', array('class' => 'btn')) }}
        </li>
    </ul>
    {{ Form::close() }}
    
    @if ($errors->any())
    <ul>
        {{ implode('', $errors->all('<li class="error">:message</li>')) }}
    </ul>
    @endif
    
    @stop
    

1 个答案:

答案 0 :(得分:0)

最后我解决了这个问题,我可以访问登录页面http://localhost/testlaravell/users/login

在routes.php上:

我换了一行:

Route::get('/users/login', array('as' => 'users.login', 'uses' =>   'UserController@getLogin'));
Route::resource('users','UserController'); 

由于我是Laravel的新手,我此前犯了这个错误。