PHP Slim Framework initial experience of inaccessible controller

Source: Internet
Author: User
Tags composer install

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.