以下是我的控制器,路由和視圖文件。Laravel 4 MethodNotAllowed異常
你能幫我解決這個問題嗎?
路由文件
Route::controller('account','AccountController');
Route::controller('course','CourseController');
Route::get('/', '[email protected]');
控制器的文件
<?php
class CourseController extends AuthorizedController
{
protected $whitelist = array(
'getCourse',
'postCourse'
);
/**
* Main users page.
*
* @access public
* @return View
*/
public function getIndex()
{
// Show the page.
//
$course = Course::all();
return View::make('course/create')->with('course', new Course());
}
public function postCourse()
{
$rules = array(
'name' => 'Required',
'has_branch' => 'Required',
'status' => 'Required',
);
$inputs = Input::all();
// Validate the inputs.
//
$validator = Validator::make($inputs, $rules);
以下是我查看
@extends('layouts.default')
{{-- Web site Title --}}
@section('title')
@parent
:: Account
@stop
{{-- New Laravel 4 Feature in use --}}
@section('styles')
@parent
body {
background: #f2f2f2;
}
@stop
{{-- Content --}}
@section('content')
<div class="page-header">
<h1>New Entery</h1>
</div>
<form method="post" action="" class="form-horizontal">
<!-- CSRF Token -->
<input type="hidden" name="csrf_token" id="csrf_token" value="{{{ Session::getToken() }}}" />
<!-- Course Name -->
<div class="control-group {{{ $errors->has('name') ? 'error' : '' }}}">
<label class="control-label" for="name">Course Name</label>
<div class="controls">
<input type="text" name="name" id="name" value="{{{ Request::old('name', $course->name) }}}" />
{{ $errors->first('name') }}
</div>
</div>
<!-- ./ course name -->
<!-- Status -->
<div class="control-group {{{ $errors->has('status') ? 'error' : '' }}}">
<label class="control-label" for="status">Status</label>
<div class="controls">
<input type="text" name="status" id="status" value="{{{ Request::old('status', $course->status) }}}" />
{{ $errors->first('status') }}
</div>
</div>
<!-- ./ last name -->
<!-- Email -->
<div class="control-group {{{ $errors->has('description') ? 'error' : '' }}}">
<label class="control-label" for="description">Description</label>
<div class="controls">
<input type="text" name="description" id="description" value="{{{ Request::old('description', $course->description) }}}" />
{{ $errors->first('description') }}
</div>
</div>
<!-- Password -->
<div class="control-group {{{ $errors->has('has_branch') ? 'error' : '' }}}">
<label class="control-label" for="has_branch">Has Branch</label>
<div class="controls">
<input type="text" name="has_branch" id="has_branch" value="" />
{{ $errors->first('has_branch') }}
</div>
</div>
<!-- ./ password -->
<!-- Update button -->
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Save</button>
</div>
</div>
<!-- ./ update button -->
</form>
@stop
當我打提交按鈕它給我:
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
代碼AuthorizedController
<?php
class AuthorizedController extends BaseController
{
protected $whitelist = array();
/**
* Initializer.
*
* @access public
* @return \AuthorizedController
*/
public function __construct()
{
parent::__construct();
// Check if the user is logged in.
$this->beforeFilter('auth', array('except' => $this->whitelist));
}
}
什麼是'AuthorizedController'? – markcial
@markcial,這是我的第一個laravel應用程序,我爲AuthorizedController添加代碼 – krish