Help / CakePHP 2 example

I cannot find a simple concrete example of how to get an argument in the CakePHP 2 shell script.

    class TestShell extends AppShell {
        public function argumentTest(){
            $parser = parent::getOptionParser();
            $parser->addArgument('testArgument', array('short' => 't','help' => 'The test argument'));
            var_dump($this->params);
        }
    }

Then I will try and name it:

  • Console / Cake TestShell argumentTest --t 45

  • Console / Cake TestShell argumentTest -t 45

  • Console / Cake TestShell argumentTest --testArgument 45

  • Console / Cake TestShell argumentTest -testArgument 45

with all of the above, I get this as an answer:

Usage:
cake lot_web_service [-h] [-v] [-q]

What am I doing wrong?

+3
source share
1 answer

You must configure the arguments when setting up the parameter parser:

public function getOptionParser() {
    $parser = parent::getOptionParser();
    //configure parser
    return $parser;
}

This ensures that the parameters and arguments are configured before sending the call. Also, from what it looks like, you want addOption()instead addArgument().

+5
source

All Articles