thomshouse-escher / escher

Escher was a PHP MVC framework developed by Thom Stricklin from 2011-2013. Escher implemented a hybrid of Model2 MVC and PAC architectures and CMS concepts as well as plugins and configuration wizards. Development halted in 2013 in favor of Kohana and later Symfony, which closely aligned to the same design principles as Escher.
http://git.io/escher
4 stars 1 forks source link

Allow controllers to dispatch requests to other controllers. (HMVC) #27

Closed thomshouse closed 12 years ago

thomshouse commented 12 years ago

Add to controllers a protected function $this->dispatch() that will route subrequests to another controller. Arguments could take the following format:

function dispatch(
    string $subcontroller,
    array $args = array(),
    array $options = array(),
    bool $display = FALSE
);

...where $subcontroller is a string of the (hookable) name of the subcontroller, args is an array of arguments to pass to the subcontroller, options is an associative array of options to provide the subcontroller, and display is a boolean determining whether the function should return rendered results (default) or display and exit.

An example of dispatching actions to a $subcontroller would be:

if ($arg[1]=='comments') {
    $this->dispatch(
        'comments',
        array_slice($args,2),
        array('content' => $entry),
        TRUE
    );
}

An example of fetching the result of a dispatched request would be:

$this->data['comments'] = $this->dispatch(
    'comments',
    array('page','1'),
    array('content' => $entry)
);

I'm still debating as to whether or not there's a better way to handle $options, whether $display is necessary, or whether dispatch() should be split into multiple functions. Part of me thinks $options is a good thing, but might result in some changes in other places (e.g. $route->instance_id). Now taking suggestions! :)

/cc @adetwiler