Exemple #1
0
	/**
	 * Fetch the template
	 *
	 * @param array $prm Array parameter for retrieve the tpl file (exemple: used to force the tpl extension via tplExt)
	 * return string The result fetched
	 * @see file::nyroExists
	 */
	public function fetch(array $prm=array()) {
		$content = null;
		$cachedContent = false;
		$cachedLayout = false;

		$oldProxy = response::getProxy();
		response::setProxy($this->responseProxy);

		$cacheResp = null;

		if ($this->cfg->cache['auto']) {
			$cache = cache::getInstance(array_merge(array('serialize'=>false), $this->cfg->cache));
			$cache->get($content, array(
				'id'=>$this->cfg->module.'-'.$this->cfg->action.'-'.str_replace(':', '..', $this->cfg->param)
			));
			$cacheResp = cache::getInstance($this->cfg->cache);
			$cacheResp->get($callResp, array(
				'id'=>$this->cfg->module.'-'.$this->cfg->action.'-'.str_replace(':', '..', $this->cfg->param).'-callResp'
			));
			if (!empty($content)) {
				$cachedContent = true;
				$cachedLayout = $this->cfg->cache['layout'];
				if (!empty($callResp)) {
					$this->responseProxy->doCalls($callResp);
					$this->responseProxy->initCall();
				}
			}
		}

		if (!$cachedContent) {
			// Nothing was cached
			$action = $this->cfg->action;
			if (array_key_exists('callback', $prm))
				$action = call_user_func($prm['callback'], $prm['callbackPrm']);
			$file = $this->findTpl($prm, array(
				'module_'.$this->cfg->module.'_view_'.$action,
				'module_'.$this->cfg->defaultModule.'_view_'.$this->cfg->default
			));

			if (file::exists($file))
				$content = $this->_fetch($file);
		}

		if ($this->cfg->layout && !$cachedLayout) {
			// Action layout
			$file = $this->findTpl($prm, array(
				'module_'.$this->cfg->module.'_view_'.$this->cfg->action.'Layout',
				'module_'.$this->cfg->module.'_view_layout'
			));
			if (file::exists($file)) {
				$this->content = $content;
				$content = $this->_fetch($file);
			}
			if ($this->cfg->cache['auto'] && $this->cfg->cache['layout'])
				$cache->save();
		}

		if ($cacheResp && $this->responseProxy->hasCall()) {
			$callResp = $this->responseProxy->getCall();
			$cacheResp->save();
		}

		response::setProxy($oldProxy);
		return $content;
	}