Php 致命错误类名必须是有效的对象或字符串

Php 致命错误类名必须是有效的对象或字符串,php,laravel,laravel-4,Php,Laravel,Laravel 4,我不熟悉laravel和php,我的控制器中有这个函数,它给了我那个错误 致命错误类名必须是有效的对象或字符串 public function getIndex () { $categories = array(); foreach ( $Category::all() as $key=> $category) { $categories[$category->id] = $category->name ; } 这是我的整个控制器 &

我不熟悉laravel和php,我的控制器中有这个函数,它给了我那个错误 致命错误类名必须是有效的对象或字符串

public function getIndex () {
    $categories = array();

    foreach ( $Category::all() as $key=> $category) {
        $categories[$category->id] = $category->name ;
    }
这是我的整个控制器

<?php 

class ProductsController extends BaseController {



public function __construct(){

    $this->beforeFilter('csrf' , array('on'=>'post')) ;
 }

public function getIndex () {
    $categories = array();

    foreach ( $Category::all() as $key=> $category) {
        $categories[$category->id] = $category->name ;
    }


    return View::make('products.index')
    ->with('products' , Product::all())
    ->with('categories' , $categories);
 }

public function postCreate(){

    $validator = Validator::make(Input::all() , Product::$rules);

    if ($validator->passes()){
        $product = new Product ; 
        $product->category_id = Input::get('category_id');
        $product->title = Input::get('title');
        $product->description = Input::get('description');
        $product->price = Input::get('price');

        $image = Input::file('image');
        $filename = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();
        Image::make($image->getRealPath())->resize(468,249)->save('public/img/products/'.$filename);
        $product->image = 'img/products/'.$filename;
        $product->save(); 

        return Redirect::to('admin/products/index')
        ->with('message' , 'Product Created');


    }
    return Redirect::to('admin/products/index')
    ->with('message', 'Something went wrong')
    ->withErrors($validator)
    ->withInput() ;
    }

public function postDestroy(){

        $product = Product::find(Input::get('id'));

        if($product){
            File::delete('public/'.$product->image);
            $product->delete() ;
            return Redirect::to('admin/products/index')
            ->with('message' , 'Product Deleted');

        }
        return Redirect::to('admin/products/index')
            ->with('message' , 'Something went wrong');


     }

    public function postToggleAvailability(){
        $product = Product::find(Input::get('id'));
        if($product){
            $product->availability = Input::get('availability');
            $product->save();
            return Redirect::to('admin/product/index')->with('message', 'product updated');

        }
        return Redirect::to('admin/product/index')->with('message' , 'Invalid Product');

    }


}

假设该类称为Category,则应在foreach中使用
Category::all()
。制作: $categories=array()


你一定有比这更好的错误消息?行号等?
$Category::all()
应该是
Category::all()
。。。。类别是一个类,而不是一个类variable@Stromgren每一行的
foreach
yes。。@Mark所说的:-)@MarkBaker谢谢。。请用这句话回答:)
foreach ( Category::all() as $key=> $category) {
    $categories[$category->id] = $category->name ;
}