Reputation: 430
I get the following message:
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}
My index file is like this:
<?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();
and InterventionsAction is like this:
<?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);
}
}
File Tree:
├── 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
So my question is maybe I setted bad some configuration values or is there something missing I should be looking for?
Upvotes: 1
Views: 840
Reputation: 17166
I assume that your autoloader can't find the files. You should search for the "autoload"
section in your composer.json and put something like the following in there:
"autoload": {
"psr-4: {
"App\\": "src/",
}
}
This assumes that your directory src/ only contains classes from the App-namespace. So src/Action/InterventionAction.php expects to contain a class with the namespace App\Action\InterventionAction
. For your tests you might want to do the equivalent in the "autoload-dev"-section.
You will also have to run a composer install
or composer update --lock
to ensure the autoloader is updated with the new information.
You might also want to read the autoloading PSRs to know how to resolve file names to classes and the composer docs:
Upvotes: 1