liuggio / ExcelBundle

Excel integration in Symfony2 thanks to https://github.com/PHPOffice/PHPExcel library
www.welcometothebundle.com
MIT License
369 stars 142 forks source link

Error: Call to a member function get() on null 500 Internal Server Error - FatalErrorException #90

Closed mobotan1 closed 9 years ago

mobotan1 commented 9 years ago

I just spent whole day but unfortunately didn't find the solution - I have done all through the instruction, but every time I receive symfony debug error: @mitsurugi Error: Call to a member function get() on null 500 Internal Server Error @

My tests show that problem starts from declaration: $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject();

PHPExcel alone works finу via // $objPHPExcel = new PHPExcel();

Please, help - where to look, what to check?

liuggio commented 9 years ago

is the bundle installed?

https://github.com/liuggio/ExcelBundle#installation

mobotan1 commented 9 years ago

Yes, sure. I did update via composer and appkernel.php... On 5 Oct 2015 12:46, "Giulio De Donato" notifications@github.com wrote:

is the bundle installed?

https://github.com/liuggio/ExcelBundle#installation

— Reply to this email directly or view it on GitHub https://github.com/liuggio/ExcelBundle/issues/90#issuecomment-145482860.

liuggio commented 9 years ago

where are you calling $this?

liuggio commented 9 years ago

BTW is not ExcelBundle related issue is how you configured test env.

liuggio commented 9 years ago

@mobotan1 if you publish some code would be possible help otherwise is not so easy.

mobotan1 commented 9 years ago

Here is my code cut I have controller function: /* @Route("/excel", name="ExcelJob") / public function ExcelAction() { $ExcelFile = "/home/my/project/1.xlsx”; $phpExcelObject = $this->get(' ExcelService')-> LoadExcelFile($ExcelFile) //…

And I have separate class:

Services.yml ExcelService: class: AppBundle\Controller\ExcelClass arguments:

class ExcelClass extends Controller {
public function LoadExcelFile($ExcelFile){ $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject($ExcelFile); return $phpExcelObject; }

liuggio commented 9 years ago

@mobotan1

  1. please use markdown
  2. please remove the cc when reply from email
  3. you have to inject the php excel into your class as collaborator $this not exist on your class $this->get('phpexcel'), you should ask on irc on any php channel.
mobotan1 commented 9 years ago

I got it! In controller -

$phpExcelObject = $this->get('##Name_Of_Service##');

In Service -

protected $container;
protected $phpexcel;

public function setContainer (\Symfony\Component\DependencyInjection\ContainerInterface $container) {
    $this->container = $container;
    $this->phpexcel = $this->container->get('phpexcel');
}

public function ExcelTest(){
    $ExcelFile = // path to Excel file
    $phpExcelObject = $this->phpexcel->createPHPExcelObject($ExcelFile);
//...
}