Where should I place my app's yiic file to exe

2019-08-09 22:25发布

问题:

When you generate Yii 1.x auto-generated application, app's private yiic is placed in protected folder. However, when I use it to execute yiic help shell, I see following message:

It is recommended that you execute this command under
the directory that contains the entry script file of
the Web application.

And then:

* entry-script | config-file: optional, the path to
the entry script file or the configuration file for
the Web application. If not given, it is assumed to be
the 'index.php' file under the current directory.

What am I missing? The protected folder is not the same folder as entry script's one (index.php). Should I move my yiic there for the purpose of executing console commands?

If yes, then why yiic is placed protected folder by default, not there, where entry script is?

If not, then why yiic assumes, that index.php exists in the same folder as yiic itself and why do I have to change this every time with using entry-script flag? This just doesn't make any sense!

I think, the answer is to keep yiic in protected folder, which is secured from web access by .htaccess file. Entry script's folder is not secured that way and is web accessible. I would personally be very worried about moving yiic to root folder, where index.php file exists. If this is the correct answer, then what is the purpose of this confusing message, cited above?

This answer seems to be supporting my idea, as it shows that CRON call should point to yiic placed in protected folder, not to the one in root folder.

Why Yii developers put yiic, where it is not supposed to be (it is looking for index.php in the same folder, so in default auto-generated application, it will fail, not finding it)? How should I understand this situation? Why I'm forced to use extra flag every time? Why default folder structure and file placement does not replicate, what yiic assumes as default?

回答1:

What the help message means is that you should execute the yiic command from the WebRoot folder (where your index.php is) like so:

% cd WebRoot
% YiiRoot/framework/yiic shell

So yii will take automatically your index.php file to do its things... But if you want to call another file like index-test.php to get yii executed instead of the default index.php you can:

% cd WebRoot
% YiiRoot/framework/yiic shell index-test.php

http://www.yiiframework.com/doc/guide/1.1/en/topics.console