【问题标题】:Where I am going wrong the the code?我在哪里出错的代码?
【发布时间】:2014-03-04 19:20:58
【问题描述】:

控制器类-

<?php
class PageController extends BaseController {
    public function home ()
    {
      $var = Testrundetail::getAll();
      return View::make('hello')->with('name', $var);
    }

    public function about ()
    {
      return View::make('about');
    }

}

模型类-

class Testrundetail extends Eloquent {
    protected $table = 'testrundetail'

    public function getAll ()
    {
      $getAll = Testrundetail::all();
      return $getAll;
    }
}

路线

Route::get('/', 'PageController@home');
Route::get('/about', 'PageController@about');

你好.blade.php

<!doctype html>

<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <h1> Hello, {{ $var }} </h1>
  </body>
</html>

我收到了错误 -

Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class 'Testrundetail' not found

1. Symfony\Component\Debug\Exception\FatalErrorException
…\app\controllers\PageController.php7

代码有什么问题?? :(

【问题讨论】:

  • 您的 Testrundetail 模型是否已自动加载?
  • 你在哪里存储 Testrundetail.php ?在app/models/ 目录中?
  • @WebNovice 是的 testrundetail.php 在 app/model 目录中
  • @SergioAristizábal 自动加载?我是这里的新手.. 请用 lil 解释说明
  • @SergioAristizábal 是这样的吗?? codefideloper.com/…code*.com/questions/17584810/…??

标签: php laravel-4


【解决方案1】:

当找不到类时,首先要检查的是它是否还没有被自动加载。

要在您的 composer.json 中自动加载文件,您需要将您的类所在的目录(如果尚未添加)添加到此部分:

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
    ],
}

一旦您确认文件夹在您的 composer.json 中,假设您正在使用 composer,您需要在您的网站根目录中运行此命令。

composer dump-autoload

希望这会有所帮助!

【讨论】:

    【解决方案2】:

    在这行后面加上;

    protected $table = 'testrundetail'
    

    作为

    protected $table = 'testrundetail';
    

    【讨论】: