symfony - calling console function in symfony2 -


i have 1 controller save data in database want run controller in crontab. make

 class getapicontroller extends controller {       public function getapiaction() {           download xml data..           saved in database used querybuilder function.....            }     } 

now try define console function

  class getapicommand extends containerawarecommand    {   protected function execute(inputinterface $input, outputinterface $output)    {  $getapicontroller =new getapicontroller();     $getapicontroller->getapiaction();    }     }  

making instance of getapi controller , try call action method there give me error that

kbundle\controller\controller.php on line 291 fatal error: call member function has() on null..

i try make controller service , try call here of

       $this->forward('app.get_controller:getapiaction'); 

they give again error forward not recognizeable

any idea how solve issue? in advance help....

you need create service job want. can use service controller , command.

this means controller , console command can both call it, , if need change it, need change in 1 place.

so if service has been registered name 'my_service', controller like;

class getapicontroller extends controller {       public function getapiaction() {           $my_service = $this->get('my_service');           $my_service->download();     } } 

and console command like;

<?php namespace mybundle\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 mycommandcommand extends containerawarecommand  {     ...     protected function execute(inputinterface $input, outputinterface $output)     {           $myservice = $this->getcontainer()->get('my_service');           $my_service->download();     } } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -