简体   繁体   English

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

[英]Pass parameters to command line using YIIC Shell

I am trying to pass parameters to command line and get the values using getopt() function. 我试图将参数传递给命令行,并使用getopt()函数获取值。 It works fine when I use 我使用时效果很好

    php file.php -a arg

But it does not show any value when I use 但是当我使用时它没有显示任何价值

    yiic shell file.php -a arg

I think I am using the incorrect syntax but I didn't get any proper result when I googled for the correct answer. 我认为我使用的语法不正确,但是当我搜索正确的答案时却没有得到任何正确的结果。 Any help will be appreciated. 任何帮助将不胜感激。 Thanks in advance! 提前致谢!

Well you just have to create a Yii command. 好吧,您只需要创建一个Yii命令。

Check this out: 看一下这个:

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

In order to create your own command with custom parameters, it should be quite easy, following this SitemapCommand example: 为了使用自定义参数创建自己的命令,遵循以下SitemapCommand示例应该非常简单:
http://www.yiiframework.com/doc/guide/1.1/en/topics.console#console-command-action http://www.yiiframework.com/doc/guide/1.1/en/topics.console#console-command-action

Why are you trying to use parameters in yiic shell command? 为什么要在yiic shell命令中使用参数? This is a special command that as far as I can see it takes only one parameter. 据我所见,这是一个特殊的命令,它仅接受一个参数。 You can see the core file at framework\\cli\\commands\\ShellCommand.php , but again I do not understand why are you messing with this command. 您可以在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.

You should use the name of your command instead of the file name. 您应该使用命令名而不是文件名。 For example, if you have a MyCommandNameCommand class that extends from CConsoleCommand you have to execute the following command from the command line: 例如,如果您有一个从CConsoleCommand扩展的MyCommandNameCommand类,则必须从命令行执行以下命令:

    yiic shell mycommandname arg1 arg2 ...

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM