0
由于控制台命令只允许声明config()
和函数,我如何声明用户定义的函数并调用它们?Symfony2 - 从命令访问用户定义的功能
由于控制台命令只允许声明config()
和函数,我如何声明用户定义的函数并调用它们?Symfony2 - 从命令访问用户定义的功能
您可以定义和调用任何功能在您的Command类:
<?php
namespace ...\Command;
use ...
class TestCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output)
{
// ...
$this->mySuperFunction();
}
protected function mySuperFunction()
{
// your code goes here...
}
}
如果你想输出的东西,然后通过你的输出对象给你的函数
$this->mySuperFunction($output);
,并使用它:
protected function mySuperFunction(OutputInterface $output)
{
$output->write('hello world!');
}
请特别说明你想要什么?当从控制台执行时,只调用'execute()'。 – 2013-05-13 14:43:45
你可以声明你喜欢的任何方法,并从执行中调用它们 – meouw 2013-05-13 14:45:18