Welcome Guest, Not a member yet? Register   Sign In
HMVC: Maintain current site and only change widget
#1

[eluser]breaddes[/eluser]
This is a pretty simple HMVC app to explain my problem.

This application loads the welcome module in site/welcome first. That's my entry point. Here I get my main content for my site and I additionally run a module called extra which gives me an extra Widgetlike content for my site.

Code:
<?php
class Welcome extends Core_Controller  {

    function __construct() {
        parent::__construct();
    }

    function index() {
        $this->data['content'] = '<h1>Hey</h1>
        modules::run('extra');
    }
}

My module extra creates a widget partial and makes it as a global string available.

Code:
&lt;?php

class Extra extends Core_Controller {

    function __construct() {
        parent::__construct();
    }

    function index() {
            $this->load->vars('widget', $this->load->view('widget', '', TRUE));
    }

    function new() {
            $this->load->vars('widget', $this->load->view('new_widget', '', TRUE));
    }

This works so far. And if I output my data in my template everything there.

Code:
&lt;?php $this->load->view('header'); ?&gt;
&lt;?=$widget?&gt;
&lt;?=$content?&gt;
&lt;?php $this->load->view('footer'); ?&gt;

Now what I want to achieve is something tricky. There is a link on the widget which should call the method new() in Extra to change the widgets view. But at the same time I don't want to leave my Welcome site, which is the corresponding current url.

If I would just call extra/new I will loose my welcome content which will later be missed in my template. So how can I maintain the current url state and still call another widget?

The only thing I can think of is creating another method in Welcome:

Code:
function other() {
        $this->data['content'] = '<h1>Hey</h1>
        modules::run('extra/new');
    }

That would do exactly what I want. But isn't it overhead to create two methods for every function I want to call. It would also mean that I don't have a good encapsulation of my extra module.
#2

[eluser]Phil Sturgeon[/eluser]
And this is exactly why people new to CodeIgniter should not be using HMVC. Use a library. Use a view with self-contained PHP code. Use an existing Widget system like wiredesignz or the one from PyroCMS.

This is not a way to work Smile
#3

[eluser]joedy[/eluser]
You can try to use some jquery functions, such as dialog, load, append, or slideDown/show




Theme © iAndrew 2016 - Forum software by © MyBB