현재 터미널에서 명령을 실행하여 CRON 작업을 수행하려고합니다. 그러나 다음과 같은 오류가 발생합니다.Symfony2에서 명령 행을 통해 CRON 작업을 실행할 수 없습니다.
PHP Fatal error: Call to a member function has() on a non-object in /MyProject/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php on line 161
이것은 내 명령 파일의 코드입니다.
namespace MyProject\UtilityBundle\Command;
use Symfony\Component\Console\Command\Command;
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 projectOngoingCommand extends Command
{
protected function configure()
{
$this
->setName('projectOngoingEstimation:submit')
->setDescription('Submit Ongoing Project Estimation')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
;
$projectController= new \MyProject\ProjectBundle\Controller\DefaultController();
$msg = $projectController->updateMonthlyOngoingAllocation();
$output->writeln($msg);
}
}
이것은 기본 컨트롤러의 코드입니다.
// cron job code
public function updateMonthlyOngoingAllocation() {
$em = $this->getDoctrine()->getEntityManager();
$project = $this->getDoctrine()->getRepository('MyProjectEntityBundle:Project')
->getAllOngoingProjectList();
return "hello";
}
이 방법은 명령 sudo php app/console projectOngoingEstimation:submit
를 사용하여 성공적이라고하지만 그것은 매우 첫 번째 줄에 오류가 발생합니다. 즉
$em = $this->getDoctrine()->getEntityManager();
컨트롤러 내에서 다른 동작 방법으로 함수를 호출하려고하면 제대로 작동합니다.