Talk not much, first put the error posted:
Just started with the slim framework, after setting up the auto-loading files and routing files, I wrote a controller:
<?PHP Use\psr\http\message\serverrequestinterface asRequest; Use\psr\http\message\responseinterface asResponse; Use\interop\container\containerinterface;classHomeController {protected $app; Public function__construct (containerinterface$ci) { $this->app =$ci; } Public functionIndex (Request$request, Response$response,$args) { Echo' Congratulations on your successful visit '; }}
and set up a route that points the index in the route to the index method in the home controller:
$app->get ('/index ', ' homecontroller:index ');
Originally want to when I visit Http://localhost/slimtest1/public/index.php/index, should print out the index method inside the text only to
I didn't expect to report the mistake I put out at the beginning.
It took a long time to find out it was my composer.json. There is no automatic load path specified, so I added the following code:
{ "require": { "Slim/slim": "^3.0" }, "AutoLoad": { "Classmap": [ "App/controllers" ] }}
The shaded section above is the newly added code that specifies the controller to go to the App/controllers folder under load.
Then execute the composer install update just fine.
Successful results:
The reason for this is that I'm not quite familiar with composer's development model. Not sure how to manage the Composer.json file
PHP Slim Framework initial experience of inaccessible controller