Welcome Guest, Not a member yet? Register   Sign In
In the interests of DRY
#7

[eluser]underskor[/eluser]
Had a few troubles with there being 0 output, then there being 2x the output, but got there in the end. For anyone who may be interested, here is the idea behind it. Hope it saves someone some time. Big thanks to Andrew for his help.
Code:
class Test extends Controller {
    var $master_view_data = array();

    function Test()    {
        parent::Controller();
        $this->master_view_data['header'] = 'HEADER';
        $this->master_view_data['footer'] = 'FOOTER';
    }

    function index() {
        $this->master_view_data['body'] = 'BODY';
    }

    function view_spoons() {
        //Get spoons
        [..]

        $this->master_view_data['body'] = $spoons;
    }
    
    function _output() {
        echo $this->load->view('master_view', $this->master_view_data, TRUE);
    }
}

A few points I had trouble with:
* _output() is called automatically, so $this->_output() at the end of your function = output x 2
* _output() does not echo your data automatically

Also, is it just me or is _output() bit counter-intuitive in regards to arguments? To pass an argument to _output(), you must call it right? (bring on the 2x output) Unless you do something like the following:
Code:
var $output;

function index() {
    $this->output = 'page';
}

function _output($this->output) {
    echo $this->output;
}

..in which case, you may aswell leave the _output() argument out? Maybe I've missed something. Anyone got any ideas?


Messages In This Thread
In the interests of DRY - by El Forum - 01-12-2009, 08:16 PM
In the interests of DRY - by El Forum - 01-13-2009, 12:14 AM
In the interests of DRY - by El Forum - 01-13-2009, 12:38 AM
In the interests of DRY - by El Forum - 01-13-2009, 12:51 AM
In the interests of DRY - by El Forum - 01-13-2009, 12:57 AM
In the interests of DRY - by El Forum - 01-13-2009, 02:17 AM
In the interests of DRY - by El Forum - 01-13-2009, 07:47 PM
In the interests of DRY - by El Forum - 01-13-2009, 11:38 PM
In the interests of DRY - by El Forum - 01-14-2009, 12:02 AM
In the interests of DRY - by El Forum - 01-14-2009, 06:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB