404 on all crud models

Hi there, I am trying to go through the basic crud tutorial but i am stuck on 404 page not found(the YII message) on every model I tried to generate.

Basically i’m up to the fourth generation, the controller, view and models and everything seems to be in place but

I keep getting the 404.

I just started to use the framework but I have now lost two days figuring this thing out, I really hope I gets better!

P.S I used the basic installation

Have you checked that the views are created in the folder app/views?

First time I used Gii I had a similar problem.

Reason was: I used the wrong view path in Gii.

Lets say you want to create GRUD for the Model "Country".

The Path for the views to use in Gii should be:

@app/views/country

It was confusing because the path for the other stuff is written without @ and backslashes.

So actually it should be:

Model: app\models\Country

Search Model: app\models\CountrySearch

Controller: app\controllers\CountryController

Views: @app/views/country

Then you should see the generated code under the URL:

http://localhost/yourProject/web/index.php?r=country/index

Regards

1 Like

Thanks, but those are the exact path I used and I have nothing.

I see the code in the controllers, models and views folder.

The code seems to be generated correctly.

I really have no idea, like i said I repeated 4 times the gii crud generator for 4 different tables and they are all 404.

I don’t know if it make any difference, but my installation is on the server, not on localhost.

I added my ip to access the debug console and of course the gii module.

Maybe you use a wrong link then?

Instead of "localhost" it should be the server-ip / url.

Can you open the Yii About-Page / Contact form etc?

Also have you setup a virtualhosts on the Server?

Please let me know a table name (you generated the crud for) and the link you try to open…

https://mega.co.nz/#!o4Qk2Sia!JynrU9ttbo_CzEF8aAigo2SdkRJUYUOCUp63853zSJc

https://mega.co.nz/#!xsphUZSZ!uUHx8JVU5UCdbtHK2sHQdr-Gj1Mpfe5XK6ek3kuXD2E

Here are some pic of the error window and my folders

No problem for the about/contact, plus I did the first part of the tutorial witch include a db connection and creating a model.

It’s only the gii code generation that doesn’t work

Sorry, but that looks weird to me. :blink:

I cant a see: app/controllers/SemaphoreController.php

When you try to open index.php?r=semaphore/index

Yii looks for a "SemaphoreController.php" and IN that Controller Yii looks for "actionIndex".

Lets say you have a database table "country".

Then you should have:

app/models/Country.php

app/controllers/CountryController.php

app/views/country/index.php

and THEN you can open:

index.php?r=country/index

Hope it is clear what I mean…

Maybe you should start a brand new project and work step by step through the guide…

(and read the whole "Application Structure" section first)

To get a better understanding of how things work together.

Best Regards

I changed the names of the views to not use the same name as the tables. But I just tried with everything the same and again nothing.

Just renaming the files will not work.

Because you will still have wrong "use statements" / wrong model names / wrong view paths in the controllers…

You should read further in the guide and first understand how things work together.

Thanks for the info.

I did read the application structure info, and when I said I renamed the models, views files I meant i regenerated the files without changing the name of the classes.

I guess it’s too bad because I reinstalled everything and again same problem, so I installed via composer and still

404, when I remove the error file I always get this message.

exception ‘ReflectionException’ with message ‘Class does not exist’ in /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/di/Container.php:415

Stack trace:

#0 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/di/Container.php(415): ReflectionClass->__construct(’’)

#1 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/di/Container.php(358): yii\di\Container->getDependencies(’’)

#2 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/di/Container.php(151): yii\di\Container->build(’’, Array, Array)

#3 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get(’’, Array, Array)

#4 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/base/Controller.php(219): yii\BaseYii::createObject(Array, Array)

#5 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/base/Controller.php(120): yii\base\Controller->createAction(‘error’)

#6 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction(‘error’, Array)

#7 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/web/ErrorHandler.php(80): yii\base\Module->runAction(‘site/error’)

#8 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/base/ErrorHandler.php(95): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))

#9 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))

#10 {main}

Previous exception:

exception ‘yii\base\InvalidRouteException’ with message ‘Unable to resolve the request “DhsPatientInfo/index”.’ in /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/base/Module.php:461

Stack trace:

#0 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module->runAction(‘DhsPatientInfo/…’, Array)

#1 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))

#2 /usr/local/apache/htdocs/dev/html/yiitest/basic/web/index.php(12): yii\base\Application->run()

#3 {main}

Next exception ‘yii\web\NotFoundHttpException’ with message ‘Page not found.’ in /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/web/Application.php:95

Stack trace:

#0 /usr/local/apache/htdocs/dev/html/yiitest/basic/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))

#1 /usr/local/apache/htdocs/dev/html/yiitest/basic/web/index.php(12): yii\base\Application->run()

#2 {main}

do one thing attach your table schema here nd screenshot of gii error so we can understand.

https://mega.co.nz/#!AtZk3DrQ!Emt5iN1bb-POWrYA9qElhki0nfYBiRsmohLNTAri_mw

https://mega.co.nz/#!5sh1nTAC!2YvfUCLkpxltV9Wfi3WFKwSYVWttq0H0QZow0Neh_m0

I tried to call the page index.php?r=dhsclinics/index, index.php?r=dhs-clinics/index,index.php?r=dhsClinics/index etc with no luck.

What did I miss?

first thing is ur attachment is not opening.

attach again model & controller of dhsclinics.

Hi! I had this problem.

Check this line on your controller,

it should be

namespace app\controllers;

not

namespace app\Controllers;

but it is generated inthe wrong way while creating thru CRUD.

1 Like

Thank you for sharing.

but it may has something wrong? I’ve tried its link but it didn’t work. :blink:

Thanks, that was the solution!!! Seems to be an error from gii…