/** * Renderiza a visão * * @return bool */ public function renderLayout() { ob_start(); $this->_renderView(); if (!$this->_noRenderLayout) { $filename = $this->_layoutDirectory . '/' . ZendT_Lib::formatNameObject($this->_layout) . '.phtml'; $result = (require $filename); if (!$result) { throw new ZendT_Exception('Invalid Layout in "' . $filename . '" '); } $reponse = ob_get_clean(); } else { $reponse = ob_get_clean(); } return $reponse; }
/** * Providencia o roteamento * * @throws ZendT_Exception */ public function dispatch() { try { /** * Detecta os parâmetros de url rewrite */ $pathInfo = $this->getRequest()->getPathInfo(); $_paramRewrite = explode('/', $pathInfo); $uriModule = $_paramRewrite[1]; $uriController = $_paramRewrite[2]; $uriAction = $_paramRewrite[3]; unset($_paramRewrite[0]); unset($_paramRewrite[1]); unset($_paramRewrite[2]); unset($_paramRewrite[3]); $module = ZendT_Lib::formatNameObject($uriModule); $controller = ZendT_Lib::formatNameObject($uriController); $action = ZendT_Lib::formatNameObject($uriAction, true); if (!is_dir($this->_moduleDirectory . '/' . $module)) { $module = ucfirst($this->_moduleNameDefault); $uriModule = $this->_moduleNameDefault; } if (!file_exists($this->_moduleDirectory . '/' . $module . '/Controller/' . $controller . '.php')) { $controller = ucfirst($this->_controllerNameDefault); $uriController = $this->_controllerNameDefault; } $className = $module . '_Controller_' . $controller; $options = array(); $options['module'] = $uriModule; $options['controller'] = $uriController; $options['action'] = $uriAction; $options['moduleDirectory'] = $this->_moduleDirectory; $options['layoutDirectory'] = $this->_layoutDirectory; $_controller = new $className($this->getRequest(), $this->getResponse(), $options); $action .= 'Action'; if (!method_exists($_controller, $action)) { $action = $this->_actionNameDefault . 'Action'; if (!method_exists($_controller, $action . 'Action')) { throw new ZendT_Exception('Action invalid!'); } else { $uriAction = $this->_actionNameDefault; } } $this->getRequest()->setParam('module', $uriModule); $this->getRequest()->setParam('controller', $uriController); $this->getRequest()->setParam('action', $uriAction); $_controller->_init(); $result = call_user_method($action, $_controller); if (is_array($result)) { foreach ($result as $key => $value) { $_controller->view->{$key} = $value; } } $this->getResponse()->setBody($_controller->view->render()); foreach ($this->_headers as $name => $value) { $this->getResponse()->setHeader($name, $value); } echo $this->getResponse()->sendResponse(); } catch (Exception $ex) { echo $ex->getMessage(); } }