问题
I was practicing to work with Yii2 based on the tutorial in this link : http://www.yiiframework.com/doc-2.0/guide-start-databases.html
I am using Advanced Application These are the files that i have created:
frontend/models/Country.php
frontend/controllers/CountryController.php
frontend/views/country/index.php
now when i try to access it using index.php?r=country/index i get 404 not found error.
But if i move the actionIndex of CountryController to SiteCountroller and rename it to actionCountry and also move my view file inside site folder (and of course change the name of index.php to country.php) then i can successfully see the list of countries using the address index.php?r=site/country
Any ideas about the 404 not found error?
回答1:
Examples in tutorial are for basic application and contains app\ in namespaces declaration. And you are using advanced application so for frontend it should begin with frontend\ (see for example SiteController in advanced application).
I think this is the reason since you said that file content is exactly the same, you didn't change default configuration and checked folders, files and classes for correct names.
来源:https://stackoverflow.com/questions/28344052/yii2-page-not-found-when-calling-country-index