我開始搭配修身+口才+小枝(使用此演示文稿http://slides.com/revul/slimframework),並得到這個錯誤:類未發現異常小井框架的路線
Type: Error
Message: Class 'Localizacao' not found
File: /Users/Bigua/Sites/salas/src/routes.php
Line: 19
我想列出所有從表並將其傳遞給我的觀點。命令「作曲家更新」不返回任何問題。
這裏我的代碼:
Composer.json:
{
"name": "slim/slim-skeleton",
"description": "A Slim Framework skeleton application for rapid development",
"keywords": ["microframework", "rest", "router", "psr7"],
"homepage": "http://github.com/slimphp/Slim-Skeleton",
"license": "MIT",
"authors": [{
"name": "Josh Lockhart",
"email": "[email protected]",
"homepage": "http://www.joshlockhart.com/"
}],
"require": {
"php": ">=5.5.0",
"slim/slim": "^3.1",
"monolog/monolog": "^1.17",
"illuminate/database": "~5.1",
"slim/twig-view": "^2.1"
},
"autoload": {
"psr-4": {
"App/Models\\": "app/models"
}
}
路線
$app->get('/sala/add', function ($request, $response, $args) {
$this->logger->info("Slim-Skeleton '/salas/add' route");
// Render index view
$args['locais'] = Localizacao::all();
$this->logger->info("locais" . $args);
return $this->renderer->render($response, 'add_sala.html.twig', $args);
})->setName('sala_add');
型號
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Localizacao extends Eloquent {
protected $table = 'localizacao';
protected $primaryKey = 'id_local';
public $timestamps = false;
}
我在這裏看過很多類似的主題,在我看來,這是命名空間的問題,但我不明白它在哪裏。對不起,如果這是一個noob問題。
[解決]
溶液其以下的兩個答案,從@馬爾欽-nabiałek和@geggleto:
修正了PSR-4:
"psr-4": {
"App\\Models\\": "app/models"
}
並正確使用名稱空間:
\App\Models\Localizacao::all()
Tnx很多!!!
THX通過標籤添加@marcin =) –