使用YIIC Shell将参数传递给命令行

时间:2015-10-27 10:44:10

标签: php yii cmd

我正在尝试将参数传递给命令行并使用getopt()函数获取值。我使用

时工作正常
    php file.php -a arg

但是当我使用

时,它没有显示任何值
    yiic shell file.php -a arg

我认为我使用的语法不正确,但当我搜索到正确的答案时,我没有得到任何正确的结果。 任何帮助将不胜感激。 提前谢谢!

2 个答案:

答案 0 :(得分:0)

嗯,你只需要创建一个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.

答案 1 :(得分:0)

您应该使用命令的名称而不是文件名。例如,如果您的MyCommandNameCommand类从CConsoleCommand扩展,则必须从命令行执行以下命令:

    yiic shell mycommandname arg1 arg2 ...

希望它有所帮助。