簡體   English   中英

使用YIIC Shell將參數傳遞給命令行

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM