How to load a codeigniter view in iframe?

Member

by mac , in category: HTML & CSS , 2 months ago

How to load a codeigniter view in iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lily , 2 months ago

@mac 

To load a CodeIgniter view in an iframe, you can simply create a controller method that loads the view and then embed this controller method in an iframe element in your HTML file.


Here's an example of how you can do this:

  1. Create a controller method in your CodeIgniter controller file (e.g., Home.php) that loads the view:
1
2
3
4
public function iframe_view()
{
    $this->load->view('your_view_name');
}


  1. Create the view file that you want to load in the iframe and save it in the views folder of your CodeIgniter project.
  2. In your HTML file, embed the controller method in an iframe element like this:
1
<iframe src="<?php echo base_url('index.php/Home/iframe_view'); ?>" width="600" height="400"></iframe>


Make sure to adjust the width, height, and controller/method name according to your requirements.


By following these steps, you should be able to load a CodeIgniter view in an iframe successfully.