2017-04-08 41 views
1

我得到以下信息:問題嘗試使用苗條3原則2

Slim Application Error 
The application could not run because of the following error: 

Details 

Type: Error 
Message: Class 'App\Action\InterventionsAction' not found 
File: /var/www/html/ws_slim/public/index.php 
Line: 53 
Trace 

#0 [internal function]: Closure->{closure}(Object(Slim\Http\Request), Object(Slim\Http\Response), Array) 
#1 /var/www/html/ws_slim/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php(41): call_user_func(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array) 
#2 /var/www/html/ws_slim/vendor/slim/slim/Slim/Route.php(344): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Http\Request), Object(Slim\Http\Response), Array) 
#3 /var/www/html/ws_slim/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): Slim\Route->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response)) 
#4 /var/www/html/ws_slim/vendor/slim/slim/Slim/Route.php(316): Slim\Route->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response)) 
#5 /var/www/html/ws_slim/vendor/slim/slim/Slim/App.php(476): Slim\Route->run(Object(Slim\Http\Request), Object(Slim\Http\Response)) 
#6 /var/www/html/ws_slim/vendor/slim/slim/Slim/MiddlewareAwareTrait.php(122): Slim\App->__invoke(Object(Slim\Http\Request), Object(Slim\Http\Response)) 
#7 /var/www/html/ws_slim/vendor/slim/slim/Slim/App.php(370): Slim\App->callMiddlewareStack(Object(Slim\Http\Request), Object(Slim\Http\Response)) 
#8 /var/www/html/ws_slim/vendor/slim/slim/Slim/App.php(295): Slim\App->process(Object(Slim\Http\Request), Object(Slim\Http\Response)) 
#9 /var/www/html/ws_slim/public/index.php(59): Slim\App->run() 
#10 {main} 

我的索引文件是這樣的:

<?php 
use \Psr\Http\Message\ServerRequestInterface as Request; 
use \Psr\Http\Message\ResponseInterface as Response; 
use App\Action\InterventionsAction; 

require 'vendor/autoload.php'; 


$app = new \Slim\App([ 
    'settings' => [ 
     'displayErrorDetails' => true 
    ] 
]); 
$app->get('/hello/{name}', function (Request $request, Response $response) { 
    $name = $request->getAttribute('name'); 
    $response->getBody()->write("Hello,, $name"); 

    return $response; 
}); 
$app->get('/api/interventions', function (Request $request, Response $response) { 
    $int = new InterventionsAction($em); 

    $response->getBody()->write("Hello,, "); 

    return $response; 
}); 
$app->run(); 

和InterventionsAction是這樣的:

<?php 
namespace App\Action; 

use Doctrine\ORM\EntityManager; 

final class InterventionsAction 
{ 
    private $em; 

    public function __construct(EntityManager $em) 
    { 
     $this->em = $em; 
    } 

    public function fetch($request, $response, $args) 
    { 
     $interventions = $this->em->getRepository('App\Entity\Interventions')->findAll(); 
     $interventions = array_map(
      function ($interventions) { 
       return $interventions->getArrayCopy(); 
      }, 
      $interventions 
     ); 
     return $response->withJSON($interventions); 
    } 

} 

文件樹:

├── cli-config.php 
├── composer.json 
├── composer.lock 
├── CONTRIBUTING.md 
├── EXPORT 
│   ├── Companies.php 
│   ├── CompaniesPlansPayments.php 
│   ├── CompaniesPlans.php 
│   ├── DepartmentsCoordinators.php 
│   ├── Departments.php 
│   ├── InterventionclasificationDetails.php 
│   ├── Interventionclasifications.php 
│   ├── Interventionrelations.php 
│   ├── Interventions.php 
│   ├── InterventiontypesCompanies.php 
│   ├── Interventiontypes.php 
│   ├── Locations.php 
│   ├── LocationTypes.php 
│   ├── Managementreview.php 
│   ├── Managementreviewrelations.php 
│   ├── Plans.php 
│   ├── ServicelinesManagers.php 
│   ├── Servicelines.php 
│   ├── Users.php 
│   └── Usertypes.php 
├── logs 
│   ├── app.log 
│   └── README.md 
├── nbproject 
│   ├── private 
│   │   └── private.properties 
│   ├── project.properties 
│   └── project.xml 
├── phpunit.xml 
├── public 
│   └── index.php 
├── README.md 
├── src 
│   ├── Action 
│   │   └── InterventionsAction.php 
│   ├── dependencies.php 
│   ├── Entity 
│   │   ├── Companies.php 
│   │   ├── CompaniesPlansPayments.php 
│   │   ├── CompaniesPlans.php 
│   │   ├── DepartmentsCoordinators.php 
│   │   ├── Departments.php 
│   │   ├── InterventionclasificationDetails.php 
│   │   ├── Interventionclasifications.php 
│   │   ├── Interventionrelations.php 
│   │   ├── Interventions.php 
│   │   ├── InterventiontypesCompanies.php 
│   │   ├── Interventiontypes.php 
│   │   ├── Locations.php 
│   │   ├── LocationTypes.php 
│   │   ├── Managementreview.php 
│   │   ├── Managementreviewrelations.php 
│   │   ├── Plans.php 
│   │   ├── ServicelinesManagers.php 
│   │   ├── Servicelines.php 
│   │   ├── Users.php 
│   │   └── Usertypes.php 
│   ├── middleware.php 
│   ├── routes.php 
│   └── settings.php 
├── templates 
│   └── index.phtml 
├── tests 
│   └── Functional 
│    ├── BaseTestCase.php 
│    └── HomepageTest.php 
└── vendor 
    ├── autoload.php 
    ├── bin 
    │   ├── doctrine -> ../doctrine/orm/bin/doctrine 
    │   ├── doctrine-dbal -> ../doctrine/dbal/bin/doctrine-dbal 
    │   ├── doctrine.php -> ../doctrine/orm/bin/doctrine.php 
    │   └── phpunit -> ../phpunit/phpunit/phpunit 
    ├── composer 
    │   ├── autoload_classmap.php 
    │   ├── autoload_files.php 
    │   ├── autoload_namespaces.php 
    │   ├── autoload_psr4.php 
    │   ├── autoload_real.php 
    │   ├── ClassLoader.php 
    │   ├── installed.json 
    │   └── LICENSE 
    ├── container-interop 
    │   └── container-interop 
    ├── doctrine 
    │   ├── annotations 
    │   ├── cache 
    │   ├── collections 
    │   ├── common 
    │   ├── dbal 
    │   ├── inflector 
    │   ├── instantiator 
    │   ├── lexer 
    │   └── orm 
    ├── monolog 
    │   └── monolog 
    ├── myclabs 
    │   └── deep-copy 
    ├── nikic 
    │   └── fast-route 
    ├── phpdocumentor 
    │   ├── reflection-common 
    │   ├── reflection-docblock 
    │   └── type-resolver 
    ├── phpspec 
    │   └── prophecy 
    ├── phpunit 
    │   ├── php-code-coverage 
    │   ├── php-file-iterator 
    │   ├── php-text-template 
    │   ├── php-timer 
    │   ├── php-token-stream 
    │   ├── phpunit 
    │   └── phpunit-mock-objects 
    ├── pimple 
    │   └── pimple 
    ├── psr 
    │   ├── container 
    │   ├── http-message 
    │   └── log 
    ├── sebastian 
    │   ├── code-unit-reverse-lookup 
    │   ├── comparator 
    │   ├── diff 
    │   ├── environment 
    │   ├── exporter 
    │   ├── global-state 
    │   ├── object-enumerator 
    │   ├── recursion-context 
    │   ├── resource-operations 
    │   └── version 
    ├── slim 
    │   ├── php-view 
    │   └── slim 
    ├── symfony 
    │   ├── console 
    │   ├── debug 
    │   ├── polyfill-mbstring 
    │   └── yaml 
    └── webmozart 
     └── assert 

所以我的問題是我可能設置了錯誤的一些配置值,或者是有一些我應該找的東西?

+0

可以向我們展示目錄結構和自動加載器配置(composer.json)? –

+0

我怎麼能告訴你這裏的完整目錄?並且我分開安裝它們,首先我得到了Slim,然後通過命令提示安裝了教條,所以我沒有得到這個 – perodriguezl

+1

的composer.json文件。這是一個盲目的猜測,但是好奇,如果你有更好的運氣,通過移動使用語句上面的'require'vendor/autoload.php'?我可能是錯的,但無論如何,錯誤消息指出'App \ Action \ InterventionsAction'類無法找到,所以我認爲這更像是一個目錄結構/文件命名/自動加載問題,而不是與Doctrine有關的問題。至少應該幫助你解決問題領域。 – stratedge

回答

1

我假定您的自動加載器找不到文件。你應該尋找在你的composer.json的"autoload"部分,並把類似的東西在那裏執行以下操作:

"autoload": { 
    "psr-4: { 
     "App\\": "src/", 
    } 
} 

這是假設你的src /目錄僅包含從App-命名空間的類。所以src/Action/InterventionAction.php期望包含一個名字空間爲App\Action\InterventionAction的類。對於你的測試,你可能想在「autoload-dev」部分做相同的操作。

您還必須運行composer installcomposer update --lock以確保自動裝載機更新爲新信息。

你也可能需要閱讀的自動加載的PSR知道如何解決文件名類和作曲家文檔: