0

I'm new at this and some help will be apprciated.

I'm building a sidebar in a CI-Boilerplate-Project which contains modules (widgets) that i got run with HMVC https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc.

In the sidebar i have a widget that display a friendslist with status online/offline. The user has the ability to switch the widgets on/off in the managementsection.

In the Profileview:

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

if box_visible == 1 the widget will be displayed.

Controller:

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);
}
}

View:

<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>

Now, i need to update the friendslist every 1-2 min so i tryed to load the moduleview within an 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>

BUT this dose not work! The place of the widget is emtpy.

Do you have any idea how to get that to work?

appreciate your help

Vinayagam
  • 944
  • 1
  • 9
  • 29
Elias
  • 1

1 Answers1

0

I believe the main issue is with the way you initialize the index method. the index method is kinda tricky with parameters in Codeigniter. In my projects, the only way to get the vlues of arguments passed to the index parameters is by using the URI library method $this->uri->segment(n). In other words, I believe that the value of $visible is not properly passing to the index() body

Anyway, I think you should create another method in your MyFriends Class called render() for example, and call it instead of relaying on the index() method. now render() can play nicely with the $visible=false initialization trick. Hope this helps

  • thanks for your answer. the problem i have is how to call "echo Modules::run()" within the src attribute of the iframe. – Elias Feb 24 '14 at 11:12
  • Oh I see. iframes embed a HTTP answer within a page at the client side. So first that url should return something so it can be embedded later. The module::run() helper will have effect on the server side, so its content must be echoed direclty within an html element in the page. At the end, glad you worked around it! – Kluverkamp Feb 24 '14 at 11:33