Database example... but for advance theme!

I’ve just downloaded the latest Yii version and I’m trying the examples from The Definitive Guide to Yii 2.0.

I downloaded the advance theme, which, compared to basic, I see that it comes with a frontend and a backend. Examples from the guide are only in basic. Nevertheless, I could do them until the Database example: yiiframework.com/doc-2.0/guide-start-databases.html . In this example, when Im try the url localhost/yii/frontend/web/index.php?r=country/index I get a 404 Not Found error. Of course I have all files under the frontend folder(and respective subfolders). I’m doing something wrong or this example is not suited for advance theme?

All code where hand written and then, when I couldn’t find the error, copy/pasted from site, so they’re ok.

And here’s my folder structure:

6613

country.jpg

EDIT: I changed the folder structure as said in post #2 (my mistake!).

EDIT 2: I have the server configured and with the requirements passed! I use Apache 2.4.9

[size="5"]SOLUTION[/size]

As example in the web are for BASIC template and not Advance template, they use app path to their namespaces (for example app/controllers). In Advance template, you should replace app for backend or frontend (according what are you working on). That’s the reason Yii couldn’t find the controller!

Move the directory "frontend/views/site/country" to "frontend/views/country". "frontend/views/site/" is meant for the Site controller.

Did that (my mistake!) but still get the 404 error. It’s like is not getting the controller, because if I put echo “something” on the public function index, also get the error. Why this could be happening?

Hi

I am trying to solve your problem by following detail.

  1. Which OS you are using? if it is linux then you need to apply correction permission to directory.

  2. Have you initiated yii application.

    If you extract yii2-advance template directly into server root directory (/var/www/)and accessing localhost/yii/frontend/web/index.php?r=country/index url then it will not. you have to init yii application. For initiating yii application by executing init file. you will find init.bat and init file in root directory of yii-advance template. you will find steps to initiate.

  3. Once application initiated, index.php and other directory will be created.

Once you follow above steps you will be able to execute above steps

  1. I’m using Windows

  2. Yes, I have initialized the application. I can see the example localhost/yii/frontend/web/index.php?r=site/say (from the documentation) but can’t the ?r=country/index. I think it can’t find the CountryController.

I reinitialized the application as DEVELOPMENT (I had it on production) and I see this error: "Unknown Class – yii\base\UnknownClassException

Unable to find ‘frontend\controllers\CountryController’ in file: C:\wamp\www\yii/frontend/controllers/CountryController.php. Namespace missing?"

The problem will be probably in yii/frontend/controllers/CountryController.php.

Have you generated the controller using Gii?

Could you paste the code of the controller here?

I found the solution and edited the original post. Moderator, feel free to close this post! :)

Please i am having the same problem as you, though am using ubuntu. Kindly share your solution(s).

Thanks in advance