0

我是新手,会得到一些帮助。

我正在 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>

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

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

感谢你的帮助

4

1 回答 1

0

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

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

于 2014-02-24T10:37:41.880 回答