【问题标题】:Load an HMVC module view within an Iframe in Codeigniter在 Codeigniter 的 Iframe 中加载 HMVC 模块视图
【发布时间】:2014-03-25 20:38:36
【问题描述】:

我是这方面的新手,希望得到一些帮助。

我正在 CI-Boilerplate-Project 中构建一个侧边栏,其中包含我使用 HMVC https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc 运行的模块(小部件)。

在侧边栏中,我有一个小部件,显示在线/离线状态的好友列表。 用户可以在管理部分打开/关闭小部件。

在个人资料视图中:

<aside class="sidebox right">
    <?php foreach ($boxes as $boxName => $boxSetting)
    {
         echo Modules::run($boxName, $boxSetting['box_visible']);
    }
    ?>
</aside>

如果 box_visible == 1 小部件将被显示。

控制器:

class Myfriends extends SM_Controller
{
function __construct()
{
    parent::__construct();
}

public function index($visible = false)
{
    $user = $this->session->userdata('user');
    $myf = $this->widget_model->get_friends($user['user_id'], 5);
    $data['friends'] = $myf;

    if ($visible) $this->load->view('myfriends', $data);
}
}

查看:

<html>
<head>
    <meta http-equiv="refresh" content="5">
</head>
<body>
<div class="box friendsbox">
  <div id="header"><h3><?=$boxTitle?></h3></div>
  <div id="boxcontent">
    <ul>
    <?php foreach ($friends as $friend): ?>
      <li>
        <div id="thb_img">
        <img src="<?=img_thumb($friend['file_path'], 50, 50) ?>" />
        </div>
        <div id="short_desc">
          <a href="<?= site_url('widget_functions/show_user/' . $friend['uu_id']) ?>">
    <?= ucfirst($friend['user_name']) . ' ' . ucfirst($friend['user_lastname']) . ' ' ?>
          </a>
        <?php if ($friend['is_online']): ?>
        <span style="color: green">online</span>
        <?php endif; ?>
        </div>
       </li>
    <?php endforeach; ?>
    </ul>
   </div>
   <div id="footer">&raquo; mehr</div>
</div>
</body>
</html>

现在,我需要每 1-2 分钟更新一次好友列表,所以我尝试在 iframe 中加载模块视图:

<aside class="sidebox right">
    <?php foreach ($boxes as $boxName => $boxSetting): ?>
    <?php if ($boxName == 'myfriends' && $boxSetting['box_visible'] == 1) { ?>
            <iframe src="<?php echo site_url('myfriends/index'); ?>" ></iframe>
        <?php
        }
        else
        {
            echo Modules::run($boxName, $boxSetting['box_visible']);
        }
    ?>
    <?php endforeach; ?>
</aside>

但是这不起作用!小部件的位置是空的。

你知道如何让它发挥作用吗?

感谢您的帮助

【问题讨论】:

    标签: codeigniter iframe module http-equiv


    【解决方案1】:

    我认为主要问题在于您初始化索引方法的方式。 index 方法对于 Codeigniter 中的参数有点棘手。在我的项目中,获取传递给索引参数的参数值的唯一方法是使用 URI 库方法 $this->uri->segment(n)。换句话说,我认为 $visible 的值没有正确传递给 index() 主体

    无论如何,我认为您应该在 MyFriends 类中创建另一个名为 render() 的方法,并调用它而不是在 index() 方法上进行中继。现在 render() 可以很好地使用 $visible=false 初始化技巧。 希望这会有所帮助

    【讨论】:

    • 感谢您的回答。我遇到的问题是如何在 iframe 的 src 属性中调用“echo Modules::run()”。
    • 哦,我明白了。 iframe 在客户端的页面中嵌入 HTTP 答案。因此,首先该 url 应该返回一些内容,以便以后可以嵌入。 module::run() 帮助器将对服务器端产生影响,因此它的内容必须在页面的 html 元素中直接回显。最后,很高兴你解决了这个问题!
    猜你喜欢
    • 2014-02-18
    • 2013-08-31
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    相关资源
    最近更新 更多