8

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.

Community
  • 1
  • 1
Sid
  • 170
  • 1
  • 1
  • 10
  • 1
    just pay simple attention to created path and view file path right path. You are missing controller folder for view files. – Kuldeep Dangi Jan 12 '15 at 06:45
  • 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. – Sid Jan 12 '15 at 11:29
  • Just noticed the same thing. My view files were also generated into the web folder. – robsch Jan 13 '15 at 09:09

9 Answers9

28

I solved similar problem by changing

backend\modules\settings\views\companies

into

@backend/modules/settings/views/companies

Hopefully it helps someone in future

Marek
  • 296
  • 2
  • 3
  • It worked I tried before using @ but didn't work because I used it with backslashes. Only works for forward slashes. If @ is used with backslashes it throws an exception on using alias. – Sid Feb 22 '15 at 04:27
2

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.

arogachev
  • 33,150
  • 7
  • 114
  • 117
  • Provide more information about the error. Is it the same or not? From what you wrote this is definitely the reason of error. – arogachev Jan 12 '15 at 07:58
  • Same error has been shown, The view file does not exist:C:\xampp\htdocs\advanced_2.0.2\backend\modules\settings\views\companies\index.php. I entered View Path: backend\modules\settings\views\companies. Still same error – Sid Jan 12 '15 at 08:14
  • Check again accurately. Did you generate files or just click "Preview" button? Maybe checkboxes are not checked. Manually check content of the view folder. If the folder or files don't exist you are doing something wrong with Gii. It's hard to tell exactly without seeing Gii and you file structure. Maybe it will be clearer with screenshots. – arogachev Jan 12 '15 at 08:23
  • And by the way your full paths are different. In question it's 'C:\xampp\htdocs\advanced\backend\modules\settings\views\companies\index.php' and in the comment - 'C:\xampp\htdocs\advanced_2.0.2\backend\modules\settings\views\companies\in‌​dex.php'. It can be the reason too. – arogachev Jan 12 '15 at 08:27
  • Checked again. I cant find the files manually. Definitely clicked on generate button. The file path issue you mention happened because I tried with yii 2.0.2 again. That's why question and comment file path differs. But for fresh approach showed the same error. – Sid Jan 12 '15 at 08:41
  • I think the current problem is related with different paths and it's kind of off topic of initial question. It has nothing to do with Gii. I guess you using the Gii in older appllication and it generates files in old path '.../advanced/...' while your current application is in '.../advanced_2.0.2/...' path. – arogachev Jan 12 '15 at 09:06
  • I tried on my initial directory that is '../advanced/..' with correct view path as you recommended, same error is thrown i,e The view file does not exist:C:\xampp\htdocs\advanced\backend\modules\settings\views\companies\in‌​dex.php. Perhaps it has something to do with the gii. – Sid Jan 12 '15 at 09:20
  • I can't help you in chat because you don't have enough reputation to access it. Provide some screenshots of Gii generation process and current file structure. – arogachev Jan 12 '15 at 09:31
2

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

1

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

/home/developer/workspace/advanced/backend/views/<your view folder> 
Jørgen R
  • 10,568
  • 7
  • 42
  • 59
1

put this in the VIEW PATH

@backend/modules/settings/views/companies

and it's done!

  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – thewaywewere Jun 16 '17 at 06:57
0

I have tried with absolute path i,e

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

It worked for the absolute path.

Sid
  • 170
  • 1
  • 1
  • 10
  • Updated my answer, maybe alias was missing? Try '@backend\modules\settings\views\companies' instead of 'backend\modules\settings\views\companies'. – arogachev Jan 14 '15 at 11:38
  • Did not work, throws exception on using alias, it shows Invalid path alias: @backend\modules\settings\views\companies – Sid Jan 15 '15 at 05:00
  • Is it presented in this file? https://github.com/yiisoft/yii2-app-advanced/blob/master/common/config/bootstrap.php – arogachev Jan 15 '15 at 05:05
  • If you mean if my bootstrap.php file consists these lines then yes. My file is same as the file you have given. – Sid Jan 15 '15 at 07:21
0

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

I hope you can do it well.

0

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()
Yair
  • 19
  • 2
0

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)

FantomX1
  • 1,577
  • 2
  • 15
  • 23