0

我尝试在 iframe 中加载 codeigniter 视图, <iframe src="<?php $this->load->view('lists');?/>"></iframe> 但页面无法加载。没有我框架它的工作。如何在 iframe 中加载此视图?

4

4 回答 4

7

在你的控制器中创建一个函数

//project.php

function view_list()
{
$this->load->view('lists');
}

并像这样在视图页面中调用

<iframe src="<?php echo site_url('project/view_list');?>">>    </iframe>
于 2013-03-19T16:14:08.483 回答
1

您不能将纯 html 分配给 iframe 元素的 src 属性。您应该有一个控制器来呈现您的 html,然后将 src 属性设置为该控制器。

<iframe src="<?php echo base_url( 'controller_that_render_list_html' ) ?>"></iframe>
于 2013-03-19T13:43:53.863 回答
1

I wanted to tile a site with several views, each in their own iframe, this is what I did:

The controller, book.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Book extends CI_Controller {


    public function index(){
        $this->shell();
    }


    public function shell(){

        $data['title'] = "Home";
        $data['frames'] = array(
            "book/events"
            ,"book/sales"
            ,"book/purchases"
            ,"book/cashflows"
        );

        $this->load->view("shell", $data);

    }


    public function events(){
        $this->load->view("events");
    }

    public function sales(){
        $this->load->view("sales");
    }

    public function purchases(){
        $this->load->view("purchases");
    }

    public function cashflows(){
        $this->load->view("cashflows");
    }


}

The view shell.php contains a foreach statement letting me pass in tiles dynamically. Note how the url's to each site are written in the controller above ^^ (eg. "book/events").

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title><?php echo $title ?></title>     
    </head>
    <body>

        <?php foreach ($frames as $frame):?>
            <iframe src="<?php echo $frame?>"></iframe>
        <?php endforeach;?>

        <div class="footer">
            Page rendered in <strong>{elapsed_time}</strong> seconds</p>
        </div>
    </body>
</html>

Then each tile is simply it's own site, like so:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Events</title>       
    </head>
    <body>
        <div class="header">Events</div>
        <div class="content"> Bla bla bla you have no money</div>
        <div class="footer">
            Page rendered in <strong>{elapsed_time}</strong> seconds</p>
        </div>
    </body>
</html>
于 2014-12-28T14:48:18.767 回答
0

这是因为 iframe 在另一个页面上?您尚未在该页面上指定控制器功能,因此它无法识别视图。我认为您必须将视图中的控制器日期放入您拥有 iframe 的视图的函数中,就像这样。

function list_view()
{
//functions for your listview
}

function viewforiframe()
{
//function for you view where the iframe is located
+
//functions for your listview
}

注意:Deon 给出的答案也是值得一看的。如果没有良好的链接,您将永远看不到视图。

于 2013-03-19T13:42:32.343 回答