Example #1
0
    /**
     * Retrieve rendered contents of a controller action
     *
     * If the action results in a forward or redirect, returns empty string.
     *
     * @param  string $action
     * @param  string $controller
     * @param  string $module Defaults to default module
     * @param  array $params
     * @return string
     */
    public function __invoke($action, $controller, $module = null, array $params = array())
    {
        $this->resetObjects();
        if (null === $module) {
            $module = $this->defaultModule;
        }

        // clone the view object to prevent over-writing of view variables
        $broker = $this->front->getHelperBroker();
        $viewRenderer = $broker->load('viewRenderer');
        $viewRendererClone = clone $viewRenderer;
        $broker->register('viewRenderer', $viewRendererClone);

        $this->request->setParams($params)
                      ->setModuleName($module)
                      ->setControllerName($controller)
                      ->setActionName($action)
                      ->setDispatched(true);

        $this->dispatcher->dispatch($this->request, $this->response);

        // reset the viewRenderer object to it's original state
        $broker->register('viewRenderer', $viewRenderer);

        if (!$this->request->isDispatched()
            || $this->response->isRedirect())
        {
            // forwards and redirects render nothing
            return '';
        }

        $return = $this->response->getBody();
        $this->resetObjects();
        return $return;
    }
Example #2
0
 /**
  * Before dispatching, digest PUT request body and set params
  *
  * @param \Zend\Controller\Request\AbstractRequest $request
  */
 public function preDispatch(\Zend\Controller\Request\AbstractRequest $request)
 {
     if (!$request instanceof \Zend\Controller\Request\Http) {
         return;
     }
     if ($this->_request->isPut()) {
         $putParams = array();
         parse_str($this->_request->getRawBody(), $putParams);
         $request->setParams($putParams);
     }
 }
Example #3
0
 /**
  * Retrieve rendered contents of a controller action
  *
  * If the action results in a forward or redirect, returns empty string.
  *
  * @param  string $action
  * @param  string $controller
  * @param  string $module Defaults to default module
  * @param  array $params
  * @return string
  */
 public function direct($action = null, $controller = null, $module = null, array $params = array())
 {
     if ($action == null || $controller == null) {
         throw new \InvalidArgumentException('Action: missing argument. $action and $controller are required in action($action, $controller, $module = null, array $params = array())');
     }
     $this->resetObjects();
     if (null === $module) {
         $module = $this->defaultModule;
     }
     // clone the view object to prevent over-writing of view variables
     $viewRendererObj = HelperBroker\HelperBroker::getStaticHelper('viewRenderer');
     HelperBroker\HelperBroker::addHelper(clone $viewRendererObj);
     $this->request->setParams($params)->setModuleName($module)->setControllerName($controller)->setActionName($action)->setDispatched(true);
     $this->dispatcher->dispatch($this->request, $this->response);
     // reset the viewRenderer object to it's original state
     HelperBroker\HelperBroker::addHelper($viewRendererObj);
     if (!$this->request->isDispatched() || $this->response->isRedirect()) {
         // forwards and redirects render nothing
         return '';
     }
     $return = $this->response->getBody();
     $this->resetObjects();
     return $return;
 }