gpt4 book ai didi

使用 php shell 的 Symfony2 脚本

转载 作者:行者123 更新时间:2023-12-01 09:06:48 27 4
gpt4 key购买 nike

如何使用 php shell 启动 Symfony2 脚本?无法使用命令直接运行Controller文件:

php FController.php

Controller 的路径是

domain.com/web/app_dev.php/fcontroller

我必须使用 Symfony2 控制台来运行这个脚本吗?

最佳答案

如前所述,您需要创建一个控制台命令。在你的一个bundle中创建一个名为'Command'的目录(这个bundle需要在AppKernel.php中注册。然后在这个目录中创建一个类,当你运行app/console时symfony会自动找到它em>。

这是一个简单的例子:

<?php
namespace Acme\FooBundle\Command;

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

class BarCommand extends Command
{

protected function configure()
{
$this
->setName('foo:bar-cmd')
->setDescription('Test command')
->addOption('baz', null, InputOption::VALUE_NONE, 'Test option');
;
}

/**
* Execute the command
* The environment option is automatically handled.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Test command');
}
}

然后您可以使用以下命令运行命令:

$> app/console foo:bar-cmd

并传入如下选项:

$> app/console foo:bar-cmd  --baz

关于使用 php shell 的 Symfony2 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6404504/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com