简体   繁体   中英

Pass parameters to command line using YIIC Shell

I am trying to pass parameters to command line and get the values using getopt() function. 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.

Check this out:

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:
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? 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.

>> 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:

    yiic shell mycommandname arg1 arg2 ...

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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