2013-09-23 37 views

回答

9

getcwd()会做你的需要。你可以从任何目录执行app/console,PHP会知道它是哪一个。

我用下面的例子来验证这一点。

<?php 

namespace Acme\DemoBundle\Command; 

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 
use Symfony\Component\Console\Input\InputArgument; 
use Symfony\Component\Console\Input\InputInterface; 
use Symfony\Component\Console\Input\InputOption; 
use Symfony\Component\Console\Output\OutputInterface; 

class DemoCommand extends ContainerAwareCommand 
{ 
    protected function configure() 
    { 
     $this 
      ->setName('demo:cwd') 
      ->setDescription('Get Current Working Directory') 
     ; 
    } 

    protected function execute(InputInterface $input, OutputInterface $output) 
    { 
     $output->writeln(getcwd()); 
    } 
} 
+1

谢谢。当从控制器(即网页)执行命令时,这是否工作? – gremo

+1

刚刚在控制器操作中进行了Symfony进程的测试,它当然可以工作。你打算用'Symfony \ Component \ Process \ Process'执行你的命令吗? –

+1

是的,也许执行和捕获输出,但它第一次将作为一个简单的控制台应用程序运行。真的非常感谢你的帮助! – gremo

相关问题