1

How to render a popup in YII controller action?

i want to open new window for some actions...please help me with this... (i want this when i call a action not when i click a link)

Ex. when i go to view action in invoice controller it should open in a new window...

is there any way to render a popup...

This is my action which generate pdf using MPDF... It should open in a new window.

public function actionReport() {
    $date=Yii::app()->Date->onlyNow();
    $name="ITEM Reprt(".$date.")";
    $mPDF1 = Yii::app()->ePdf->mpdf('L', 'A5');
    $mPDF1->WriteHTML($this->renderPartial('test', array(), true));
    $mPDF1->Output($name,'I');

}

THANKS...!

Harsha Tharanga
  • 94
  • 4
  • 16
  • I dont know other ways then use js. i use it on link ` Print`. If you want it on action try to register it in beforeAction. – ineersa Sep 11 '13 at 06:59
  • I don't get why people still use popups. Why would you need a second page to open the document? You could output the PDF directly so it opens in the browser or as a download. Or even display it inside a div / iframe. – tlenss Sep 11 '13 at 07:03
  • You cannot interact with client from server, i.e. the client needs to open the popup for you, using window.open, for example. You then just point the url to your report action. – Martin Komara Sep 11 '13 at 07:16
  • i want current window and new window both...if i can generate pdf in a new window that would be gr8t... – Harsha Tharanga Sep 11 '13 at 07:17
  • can i directly render a popup – Harsha Tharanga Sep 11 '13 at 07:19

1 Answers1

1

Why popups? Simply create link with target="_blank", browser will open new window or new tab - per user preferences.

<a href="<?= Yii::app()->createUrl('report', array(/* params */));?>" target="_blank">Print PDF!</a>

You can even embed pdf or use pdfobject etc.

Community
  • 1
  • 1