A few days ago i took a look at the proposal, its a good implementation for
the view object, but unfortunately i couldn't use my front controller
plugins - like ACL checking - without reinventing.
Another issue for me was merging the injected data for the view object. i
dont know how far the view enhanced proposal goes, i wanted to get the view
and native data of the view and individualy replace the views data by the
view/widget caller. i also implemented a layout wrapper. the widget helper
looks like:
class RF_View_Helper_Widget extends RF_View_Helper
{
public static $passThroughParamsRecursive = true;
/**
* This method returns the response of a virtual subrequest.
*
* @author Markus Siebeneicher <[EMAIL PROTECTED]>
*
* proxies to [EMAIL PROTECTED] widgetUri()}
*
* @param string $action
* @param string $controller
* @param string $module
* @param array $params URI Parameter aka Query Params
* @param array $passThroughParams params for the front controller
* @return Zend_Controller_Response_Http
*/
public static function widget($action, $controller = NULL, $module =
NULL, $params = array(), $passThroughParams = array())
{
return self::widgetUri(RF_Helper::makeZendUri($action,
$controller,
$module, $params, $passThroughParams));
}
/**
* This method returns the response of a virtual subrequest.
*
* @author Markus Siebeneicher <[EMAIL PROTECTED]>
*
* @todo widget output/errors handeln
*
* @param string|Zend_Uri $uri
* @param array $passThroughParams params for the front controller
* @return Zend_Controller_Response_Http
*/
public static function widgetUri($uri, $passThroughParams = array()) {
$frontParent = RF_Controller_Front::getInstance();
if(self::$passThroughParamsRecursive === true)
if(count((array)
$frontParent->getRuntimeParam("widgetPassThroughParams")) > 0)
$passThroughParams =
self::mergePassThroughParams(
$passThroughParams,
$frontParent->getRuntimeParam("widgetPassThroughParams")
);
$front = RF_Controller_Front::initFrontController($frontParent);
$front->setRuntimeParam("widgetPassThroughParams",
$passThroughParams);
$request = new Zend_Controller_Request_Http($uri);
$response = new Zend_Controller_Response_Http();
ob_start();
$t1 = microtime(true);
$front->dispatch($request, $response);
$t2 = microtime(true);
Zend_Registry::getInstance()->rfLogger->log("Time used to dispatch
widget(". $front->getRequest()->getRequestUri() ."): ". ($t2-$t1),
Zend_Log::DEBUG);
//$front->getResponse()->setBody(ob_get_contents());
ob_end_clean();
RF_Controller_Front::destroyLastInstance();
//unset($front);
return $response;
}
/**
* hier werden zwei arrays gemerged, die elemente werden dem major vom
minor angehangen,
* wenn der key im major noch nicht existiert
*
* @author Markus Siebeneicher <[EMAIL PROTECTED]>
*
* @param array $majorParams
* @param array $minorParams
* @return array
*/
private static function mergePassThroughParams($majorParams,
$minorParams)
{
//print_r($minorParams);
//print_r($majorParams);
foreach($minorParams AS $_key => $_value) {
if(isset($majorParams[$_key])) {
if(is_array($majorParams[$_key]) &&
is_array($minorParams[$_key])) {
$majorParams[$_key] =
self::mergePassThroughParams($majorParams[$_key], $minorParams[$_key]);
}
} else {
$majorParams[$_key] = $_value;
}
}
return $majorParams;
}
}
Simon Mundy wrote:
>
> You may wish to review Matthew's first commit in the incubator for the
> Zend_View_Helper_Action component.
>
> It's the official Zend implementation of Padraic's Zend_View_Enhanced
> - the Action Helper solves exactly the problem you've described here.
> Check it out, give it a try and see if you can add your feedback to
> the proposal (would give you the link but the Wiki's down :( )
>
> Cheers
>
>> Hey folks,
>>
>> in my current project i built up a widget system based on ZF which
>> allowes
>> to run a front controller twice or more during runtime and getting the
>> response of a so called subrequest in a view with:
>>
>> <div id="calendar">
>> <?php echo $this->widget("calendar", "utils", "global-module"); ?>
>> </div>
>>
>> This post is for those who are interested in chaining the front
>> controller
>> object and getting allways the right instance when calling
>> Zend_Controller_Front::getInstance().
>>
>> The Problem with current Zend_Controller_Front is, that it
>> implements the
>> singelton pattern and it allways give the current instance back.
>> that means,
>> its not possible to have more than one instance at the same time. of
>> course,
>> this behavior is neccessary for the helperbrooker, but this is another
>> topic.
>
> --
>
> Simon Mundy | Director | PEPTOLAB
>
> """ " "" """""" "" "" """"""" " "" """"" " """"" " """""" "" "
> 202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
> Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654
> 4124
> http://www.peptolab.com
>
>
>
--
View this message in context:
http://www.nabble.com/chaining-the-front-controller-tf4625668s16154.html#a13210594
Sent from the Zend Framework mailing list archive at Nabble.com.