8
votes

I am new to yii framework. On yii version:2.0.1 I have created a module in which I tried to generate a CRUD model using the gii functionality.
After putting the model class, controller class and view path when I clicked on generate gii showed all the files has been created successfully.
But when I tried to view, below message has been shown to me,

The view file does not exist :

C:\xampp\htdocs\advanced\backend\modules\settings\views\companies\index.php

I found the view files in web directory not in the path I entered. Hence the error.

Here is my inputs to gii,

Model Class:

backend\modules\settings\models\Companies

Search Model Class:

backend\modules\settings\models\CompaniesSearch

Controller Class:

backend\modules\settings\controllers\CompaniesController

View Path:

backend\modules\settings\views\companies

When I click generate I have given below message :

Generating code using template "C:\xampp\htdocs\advanced\vendor\yiisoft\yii2-gii\generators\crud/default"...

generated modules\settings\controllers\CompaniesController.php

generated modules\settings\models\CompaniesSearch.php

generated backend\modules\settings\views\companies\_form.php

generated backend\modules\settings\views\companies\_search.php

generated backend\modules\settings\views\companies\create.php

generated backend\modules\settings\views\companies\index.php

generated backend\modules\settings\views\companies\update.php

generated backend\modules\settings\views\companies\view.php

done!

Does anybody have any idea why is it happening.

Thanks in advance.

9
just pay simple attention to created path and view file path right path. You are missing controller folder for view files.Kuldeep Dangi
I did found where the view files being generated, they are generated at C:\xampp\htdocs\advanced\backend\web\modules\settings\views\companies directory. I can copy them to intended directory. But still can not generate the view files where they should be.sidrat
Just noticed the same thing. My view files were also generated into the web folder.robsch

9 Answers

28
votes

I solved similar problem by changing

backend\modules\settings\views\companies

into

@backend/modules/settings/views/companies

Hopefully it helps someone in future

2
votes

You missed one final folder and alias in View Path. It should be @backend\modules\settings\views\companies.

As you can see in creation log, the generated files are in wrong place (root views folder), that's why the error is thrown.

2
votes

Have the same problem. Solved entering @backend/modules/settings/views/companies instead backend\modules\settings\views\companies. See on slashes.

1
votes

For view path in CRUD generator, enter the absolute or full path. For example

/home/developer/workspace/advanced/backend/views/<your view folder> 
1
votes

put this in the VIEW PATH

@backend/modules/settings/views/companies

and it's done!

0
votes

I have tried with absolute path i,e

C:/xampp/htdocs/advanced/backend/modules/settings/views/companies

It worked for the absolute path.

0
votes

I tried this is working by entering: /Applications/XAMPP/htdocs/advanced/backend/modules/settings/views/companies

I hope you can do it well.

0
votes

I'm using the advanced theme

Here is my Gii setup in case it is helpful for anyone

module generator
----------------
module class:       backend\modules\posts\Module
module id:          posts

model generator
---------------
table name:         posts
model class:        Posts
namespace:          backend\modules\posts\models
Enable I18n:        checked. category: app

CRUD generator
--------------
Model class:        backend\modules\posts\models\Posts
Search model class: backend\modules\posts\models\PostsSearch
Controller class:   backend\modules\posts\controllers\PostsController
View path:          @backend/modules/posts/views/posts
Enable I18n:        checked. category: app
Enable pjax:        checked

If you are using some non-default user management (like amnah module), 
you need to change Users::className() in the models\Posts.php  to
\amnah\yii2\user\models\User::className()
0
votes

Previously I put a model into the incorrect directory when wanting to achieve an absolute path (address it absolutely as it seems to be more often functional) -

app/backend/modules/settings .

Notice the 'app' in the beginning (the /app is the main directory in Yii starter kit) which I thought would avoid the relative path but must NOT be there nor @mail sign, but on the contrary, it did the opposite - it appended it relatively with its absolute length to the /document root directory, basically duplicated it,

"app/myproject.com/app/backend/modules/settings"

So it unwinds from the model location, the causes of Gii complaints about incorrect paths or put also controllers the incorrect way.

Also strangely enough for views in contrast to models, it had to be put the upper mentioned different way with the @ relative reference sign annotation (which was not allowed to be used for controllers or models at the time of writing)

@backend/modules/settings/views/companies, otherwise it appended the directory tree into the document root, again concatenated - the web directory of backend backend/web (backend/modules/settings/views/companies)