2014-02-24 119 views
0

我是新手,並且會有一些幫助。在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">&raquo; 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。

你有什麼想法如何得到這個工作?

感謝您的幫助

回答

0

我認爲主要的問題是你初始化索引方法的方式。索引方法在Codeigniter中的參數有點棘手。在我的項目中,獲取傳遞給索引參數參數的唯一方法是使用URI庫方法$ this-> uri-> segment(n)。換句話說,我認爲$ visible的值並沒有正確傳遞給index()主體

無論如何,我想你應該在MyFriends類中創建另一個名爲render()的方法,例如調用它在index()方法上進行中繼。現在render()可以很好地與$ visible = false初始化技巧一起玩。 希望這會有所幫助

+0

感謝您的回答。 我遇到的問題是如何在iframe的src屬性中調用「echo Modules :: run()」。