致命错误:Class' BaseController'未找到

时间:2014-09-09 08:20:42

标签: php laravel laravel-4

我正在逐步从教程中学习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');    
     }
}
?>

我的项目应用程序文件夹的树 tree

3 个答案:

答案 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')) ;
     }
     ......
}

希望它有所帮助!