Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example code issue #23

Open
Bhoft opened this issue Feb 20, 2018 · 3 comments
Open

example code issue #23

Bhoft opened this issue Feb 20, 2018 · 3 comments
Labels

Comments

@Bhoft
Copy link

Bhoft commented Feb 20, 2018

Hi I wanted to test your pdf formatter and have some issue with your given example code.

https://github.com/robregonm/yii2-pdf#usage

I have added the code into the config.
But whenever i want to overrule some settings in the Controller::actionPdf as given in your example the settings don't change from the original ones.

e.g. if i set the orientation to "Landscape" when in the config the default is "Portrait".

Could it be that your Dependency Injection code doesn't work?

I would have to set it like this so that the settings are changed in the action.

public function actionPdf(){
    Yii::$app->response->format = 'pdf';
    Yii::$app->response->formatters['pdf']['orientation'] = 'Landscape';
    Yii::$app->response->formatters['pdf']['format'] = [216, 356];
    $this->layout = '//print';
    return $this->render('myview', []);
}

Is this correct?

@Bhoft
Copy link
Author

Bhoft commented Feb 20, 2018

i see that in the past there was also some issue with this code
#10

Is there something wrong with this example or was something change within yii2 since 2015 so that the modifications to the attribute set over the container aren't used?

just to clarify:
I understand that there are changes to the mdf class itself. But my question is more why the changed attributes aren't taken over to when i just echo the orientation inside the class in the format function.

@robregonm
Copy link
Owner

@Bhoft No changes since then. Did you enable pdf in response formatters?

@Bhoft
Copy link
Author

Bhoft commented Mar 28, 2018

Of course i have enabled it. As i have written if i take your example code and change a setting e.g. marginLeft to another value as it is set in the config file (15=>45)

  Yii::$app->response->format = 'pdf';
  Yii::$container->set(Yii::$app->response->formatters['pdf']['class'], [
	 'marginLeft' => 45
  ]);

And check what the value is inside the PdfResponseFormatter class, the margin is still 15 as given in the config.

If i use the following the value is correctly changed.

Yii::$app->response->formatters['pdf']['marginLeft'] = 45;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants