开发者

Simple Code Igniter sidebar implementation? How?

I posted a thread a few days back but it didn’t take the direction I was looking for, so I will try again and fingers cross explain a little better.

I have a list of controllers.. Home, League, Forum as so on. Once the controller has its data it calls down to a view named template which in turn calls the default header, footer, content and sidebar views. (The content variable is set by the controller).

So far so good, this works great until I realise the need the sidebar data to be dynamic instead of its current static state.. Now as the site grows larger I would prefer not to have to sp开发者_如何学Pythonecify the data that gets called for the sidebar each time.

I would prefer to set a variable in the controller that loads “widgets” possibly, I see this being done in the template view, however I know controllers can not be called in view, so I am stuck.

$sidebar = array(‘latest_news’,‘latest_forum’);

Currently I am emulating this affect with Ajax… I specify a list of variables in the controller. The template loops the variables and does an Ajax request for each required widget, pushing them into a div..

There must be a better way… Example: http://dev.banelingnest.com/

Now i have looked at HMVC and i cant wrap my head around it. It rather seems bloated for my limited requirements. Does anyone have a nice and simple way of achieving this?

Thanks in advance.. Korhal


As it's most simple, set a variable to do whatever in the controller, then just send that as one of the variables to the view...

Controller:

 $data['widget'] = $this->show_widget('time'); // widget output
 $this->load->view('sidebar', $data);

Sidebar view:

<div class="sidebar">
  <?php if (isset($widget)) echo $widget; ?>
</div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜