Home > Enterprise >  CodeIgniter 4 view
CodeIgniter 4 view

Time:07-24

Any one can tell me how to view a PHP page in a new tab from CodeIgniter 4 controller. I tried this code:

return view('/pdfrepo/resume-page-pdf',$data, array('target' => '_blank'));

the page is viewed with no error at all, but on the same tab!.

CodePudding user response:

rendering a view is not the same as clicking on a link:

rendering a view: if you look at the docs Global Functions and Constants - view you'll see that third "options" parameter you are using is meant for a completely different concept as you try to apply it to, like the styling of an <a href>, which in your example doesn't even exist (yet):

$options (array) – An array of options that will be passed to the rendering class. Currently, these options are available for use within the $options array: saveData, cache, debug

clicking a link: check the documentation URL Helper - anchor where you would use the attributes parameter to add something like: ['target' => 'blank'] to achieve a link which opens a new tab

P.S. _blank: usually a new tab, but users can configure browsers to open a new window instead.

CodePudding user response:

PHP can't open a new tab and display the data. PHP is a Server Side Language. for this, you have to use a Client Side Language such as JavaScript.

In your main view

<a href="<?= base_url('controller/route') ?>" target="_blank">View PDF</a>

target="_blank" which performs the miracle that loads the page in a new tab.

  • Related