我正在逐步从教程中学习laravel4但是在尝试访问CategoriesController.php
时它给了我错误,尽管控制器文件夹中有BaseController.php
!!
那是CategoriesController
<?php
class CategoriesController extends BaseController {
public function __construct(){
$this->beforeFilter('csrf' , array('on'=>'post')) ;
}
public function getIndex () {
return View::make('categories.index')
->with('categories' , Category::all());
}
public function postCreate(){
$validator = Validator::make(Input::all() , Category::$rules);
if ($validator->passes()){
$category = new Category ;
$category->name = Input::get('name');
$category->save();
return Redirect::to('admin/categories/index')
->with('message' , 'Category Created');
}
return Redirect::to('admin/categories/index')
->with('message', 'Something went wrong')
->withErrors($validator)
->withInput() ;
}
public function postDestroy(){
$category = Category::find(Input::get('id'));
if($category){
$category->delete() ;
return Redirect::to('admin/categories/index')
->with('message' , 'Category Deleted');
}
return Redirect::to('admin/categories/index')
->with('message' , 'Something went wrong');
}
}
?>
我的项目应用程序文件夹的树
答案 0 :(得分:0)
尝试运行 php artisan dump-autoload 和 composer dump-autoload 重新生成自动加载文件
答案 1 :(得分:0)
这不是问题,但你永远不会知道..试试这个:class CategoriesController extends \BaseController
在BaseController之前注意\
答案 2 :(得分:0)
你需要在类之前放置“namespace”和“use Illuminate”,并且扩展到“Controller” NOT到“BaseController”,所以试试这个:< / p>
希望它有所帮助!<?php
/*
* you need to put these 2 lines before your "Class"
* //////////////////////////////////////////////////
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
///////////////////////////////////////////////////
class CategoriesController extends Controller {
public function __construct(){
$this->beforeFilter('csrf' , array('on'=>'post')) ;
}
......
}