[英]Pass parameters to command line using YIIC Shell
我试图将参数传递给命令行,并使用getopt()
函数获取值。 我使用时效果很好
php file.php -a arg
但是当我使用时它没有显示任何价值
yiic shell file.php -a arg
我认为我使用的语法不正确,但是当我搜索正确的答案时却没有得到任何正确的结果。 任何帮助将不胜感激。 提前致谢!
好吧,您只需要创建一个Yii命令。
看一下这个:
http://www.yiiframework.com/doc/guide/1.1/en/topics.console
为了使用自定义参数创建自己的命令,遵循以下SitemapCommand示例应该非常简单:
http://www.yiiframework.com/doc/guide/1.1/en/topics.console#console-command-action
为什么要在yiic shell命令中使用参数? 据我所见,这是一个特殊的命令,它仅接受一个参数。 您可以在framework\\cli\\commands\\ShellCommand.php
看到核心文件,但是同样,我不明白您为什么要弄乱这个命令。
>> yiic help shell
USAGE
yiic shell [entry-script | config-file]
DESCRIPTION
This command allows you to interact with a Web application
on the command line. It also provides tools to automatically
generate new controllers, views and data models.
It is recommended that you execute this command under
the directory that contains the entry script file of
the Web application.
PARAMETERS
* 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.
您应该使用命令名而不是文件名。 例如,如果您有一个从CConsoleCommand
扩展的MyCommandNameCommand
类,则必须从命令行执行以下命令:
yiic shell mycommandname arg1 arg2 ...
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.