php - Get returned of controller action in my own abstact library (Zend Framework) -
hello trying retrieve values returned controller action in own library abstract in 1 of methods of dispatch of zend framework, wonder if feat possible , if how it.
my code follows:
indexcontroller
class indexcontroller extends my_controller { public function init() { /* initialize action controller here */ } public function indexaction() { // action body return 'hello world'; } }
my_controller
abstract class my_controller extends zend_controller_action { /** * initialize core_controller * @param zend_controller_request_abstract $request * @param zend_controller_response_abstract $response * @param array $invokeargs */ public function __construct(zend_controller_request_abstract $request, zend_controller_response_abstract $response, array $invokeargs = array()) { parent::__construct($request, $response, $invokeargs); $this->_helper->viewrenderer->setnorender(); } public function predispatch() { //something here } public function postdispatch() { //something here } public function dispatch() { //something here } }
i need value of returned in controllador in library in order transform json , print screen.
thnk
in zf 1 there isn't way return value controller action. value never used or captured zend framework itself.
take @ zend/controller/action.php
line 516 (zf 1.11.11) , point zf calls controller action, , return value not captured or used.
public function dispatch($action) { // notify helpers of action predispatch state $this->_helper->notifypredispatch(); $this->predispatch(); if ($this->getrequest()->isdispatched()) { if (null === $this->_classmethods) { $this->_classmethods = get_class_methods($this); } // if pre-dispatch hooks introduced redirect stop dispatch // @see zf-7496 if (!($this->getresponse()->isredirect())) { // predispatch() didn't change action, can continue if ($this->getinvokearg('usecasesensitiveactions') || in_array($action, $this->_classmethods)) { if ($this->getinvokearg('usecasesensitiveactions')) { trigger_error('using case sensitive actions without word separators deprecated; please not rely on "feature"'); } $this->$action(); // <--- line 516 - calls action } else { $this->__call($action, array()); } } $this->postdispatch(); } // whats important here action controller // shutting down, regardless of dispatching; notify helpers of // state $this->_helper->notifypostdispatch(); }
as can see, value returned controller never used. also, in zf2, changing way controller actions work return values have meaning may want think of different approach.
the quickest thing can think of @ moment instead of trying return value controller, set registry value can fetch later.
e.g.
public function returnaction() { // ... zend_registry::set('controller_return_value', 'hello world'); }
and later, in plugin or wherever trying value:
try { $retval = zend_registry::get('controller_return_value'); } catch (zend_exception $ex) { $retval = null; // no return value set controller }
Comments
Post a Comment