Symfony 3プロジェクトでcronを作成しようとしました。私のコントローラーをSymfony3で使用するCrontab
XMLファイルのデータを保存するために私のコントローラーに関数を作成しました。コンソール上で何を呼び出すべきか私はエラーがあり、これはわかりません。
これは私の最初のSymfonyプロジェクトです。私のコードで何が間違っているのか分かりません。私はPHPのbin /コンソールアプリケーションを実行したときに
を私はthis solutionを見てきましたが、私は私のproblemeを解決することはできませんこれは、コンソールからのエラーです:保存-XML-データ
PHP Fatal error: Call to a member function get() on a non-object in /data/www/weatherperf/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php on line 412
PHP 9. Symfony\Bundle\FrameworkBundle\Controller\Controller->get() /data/www/weatherperf/src/Core/LayoutBundle/Controller/LayoutController.php:125
[2017-10-11 13:14:38] php.CRITICAL: Fatal Error: Call to a member function get() on a non-object {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 0): Error: Call to a member function get() on a non-object at /data/www/weatherperf/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php:412)"}
[Symfony\Component\Debug\Exception\FatalErrorException]
Error: Call to a member function get() on a non-object
マイコントローラー
バンドルservices:
core_layout.setxmldata:
class: Core\LayoutBundle\Controller\LayoutController
arguments: ['@doctrine.orm.entity_manager']
のための私のservices.yml
<?php
class LayoutController extends Controller
{
private $sNameController = "CoreLayoutBundleLayout";
private $em = null;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
/**
* @Route("/xml_uploadData", name="core_layout_xml_upload")
*/
public function setXmlData()
{
$sTimestamp = date(time());
$this->get('admin_layout.log')->addLogTo("getData", "Début Traitement", "SaveData", $this->sNameController);
//....
}
}
あなたはここに 'コントローラ' を使用している理由
マイcommande
<?php
namespace Core\LayoutBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
class SetXmlDataCommand extends ContainerAwareCommand
{
protected function configure()
{
// the name of the command (the part after "php bin/console")
$this->setName('app:save-xml-data')
->setDescription('Save data from XML file')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// outputs a message to the console followed by a "\n"
$output->writeln('Debut de la commande de sauvegarde');
// access the container using getContainer()
$saveService = $this->getContainer()->get('core_layout.setxmldata');
$results = $saveService->setXmlData();
$output->writeln($results);
}
}
[Minimal](https://stackoverflow.com/help/mcve)のサンプルはどうですか? – svgrafov
@svgrafov:投稿を編集した方がいいかもしれない。 –
私が提供したリンクを実際に読んだことはありますか?あなたの例ではコードの量を減らそうとするべきです。あなたの推測はまったく助けません。 – svgrafov