我是新手,並且會有一些幫助。在Codeigniter的Iframe中加載HMVC模塊視圖
我在CI-Boilerplate-Project中構建了一個邊欄,其中包含我用HMVC運行的模塊(小部件)。
在邊欄中,我有一個小部件,顯示狀態在線/離線的好友列表。 用戶可以在管理部分中打開/關閉小部件。
在Profileview:
<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">» mehr</div>
</div>
</body>
</html>
現在,我需要更新friendslist每1-2分鐘所以我tryed的iframe中加載moduleview:
<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>
但是這個劑量不行!小部件的地方是emtpy。
你有什麼想法如何得到這個工作?
感謝您的幫助
感謝您的回答。 我遇到的問題是如何在iframe的src屬性中調用「echo Modules :: run()」。
哦,我明白了。 iframe在客戶端的頁面中嵌入HTTP答案。所以首先,url應該返回一些東西,以便以後可以嵌入。 module :: run()helper將在服務器端產生影響,所以它的內容必須在頁面的html元素中直接回顯。最後,很高興你能解決它! – Kluverkamp