createTemplate bez parametra

pisa98
Člen | 17
+
0
-
<?php

use Nette\Application\UI\ITemplateFactory;

interface PdfExportFactory extends BaseExportFactory
{
    /** @return PdfExport */
    public function create();
}
class PdfExport extends BaseExport
{
    /** @var ITemplateFactory */
    private $templateFactory;

    public function __construct(ITemplateFactory $ITemplateFactory)
    {
        $this->templateFactory = $ITemplateFactory;
    }

    public function createFile()
    {
        $template = $this->templateFactory->createTemplate();
        $template->items = $this->items;
        $template->setFile(__DIR__ . '/pdf.latte');

        $pdf = new \Joseki\Application\Responses\PdfResponse($template);
        // optional
        $pdf->documentTitle = date("Y-m-d") . '-' .$this->requestId;
        $pdf->pageFormat = "A4";
        $pdf->save($this->getFolder($this->requestId));

    }
}

Mam problem s metodou createTemplate() pretoze prebera parameter objekt ktory extenduje od Nette\UI. Na nette 2.3 je ten parameter null a ja mam nette 2.2 a potreboval by som to fungovalo na nette 2.2 a neviem cim to nahradit alebo ako. Vedeli by ste mi pomoct? Dakujem

Barbarossa
Člen | 74
+
+1
-

V nette 2.2 si asi musíš vzít Latte/Engine a vyrenderovat si výstup pro PdfResponse, viz doc 2.2

class PdfExport extends BaseExport
{
    /** @var \Latte\Engine; */
    private $latte;

    public function __construct(ILatteFactory $ILatteFactory)
    {
        $this->latte = $ILatteFactory->create();
    }

    public function createFile()
    {
		$params = array(
    		'items' => $this->items,
		);

        $template = $this->latte->renderToString(__DIR__ . '/pdf.latte', $params);
		$pdf = new \Joseki\Application\Responses\PdfResponse($template);

        // optional
        $pdf->documentTitle = date("Y-m-d") . '-' .$this->requestId;
        $pdf->pageFormat = "A4";
        $pdf->save($this->getFolder($this->requestId));

    }
}

Editoval Barbarossa (23. 7. 2018 13:33)

pisa98
Člen | 17
+
0
-

Diky moc pomholo mi to

Barbarossa napsal(a):

V nette 2.2 si asi musíš vzít Latte/Engine a vyrenderovat si výstup pro PdfResponse, viz doc 2.2

class PdfExport extends BaseExport
{
    /** @var \Latte\Engine; */
    private $latte;

    public function __construct(ILatteFactory $ILatteFactory)
    {
        $this->latte = $ILatteFactory->create();
    }

    public function createFile()
    {
		$params = array(
    		'items' => $this->items,
		);

        $template = $this->latte->renderToString(__DIR__ . '/pdf.latte', $params);
		$pdf = new \Joseki\Application\Responses\PdfResponse($template);

        // optional
        $pdf->documentTitle = date("Y-m-d") . '-' .$this->requestId;
        $pdf->pageFormat = "A4";
        $pdf->save($this->getFolder($this->requestId));

    }
}