CakePdf\Pdf\CakePdf::template PHP Method

template() public method

Template and layout
public template ( mixed $template = false, mixed $layout = null ) : mixed
$template mixed Template name or null to not use
$layout mixed Layout name or null to not use
return mixed
    public function template($template = false, $layout = null)
    {
        if ($template === false) {
            return ['template' => $this->_template, 'layout' => $this->_layout];
        }
        $this->_template = $template;
        if ($layout !== null) {
            $this->_layout = $layout;
        }
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * testPluginOutput
  *
  * @dataProvider provider
  */
 public function testPluginOutput($config)
 {
     $pdf = new CakePdf($config);
     Plugin::load('MyPlugin', ['autoload' => true]);
     $pdf->viewVars(['data' => 'testing']);
     $pdf->template('MyPlugin.testing', 'MyPlugin.pdf');
     $pdf->helpers('MyPlugin.MyTest');
     $result = $pdf->output();
     $expected = 'MyPlugin Layout Data: testing';
     $this->assertEquals($expected, $result);
     $pdf->template('MyPlugin.testing', 'MyPlugin.default');
     $result = $pdf->output();
     $lines = ['<h2>Rendered with default layout from MyPlugin</h2>', 'MyPlugin view Data: testing', 'MyPlugin Helper Test: successful'];
     foreach ($lines as $line) {
         $this->assertTrue(strpos($result, $line) !== false);
     }
 }