Пример #1
0
 /**
  * Adds a block to a controller layout
  *
  * Layout block is an atomic part of application which cannot be called directly
  * by a user. Block fills a layout which encapsulates currently executed action
  * (some kind of contextual menu or environment depending on application part)
  *
  * Usage (lets say it is a body of some controller action)
  * <code>
  *
  * // Generates output of newsListBlock() by using block/newList.tpl template (by default)
  * // and assigns an output to an APPLICATION_NAV template variable.
  *
  * $this->addBlock("APPLICATION_NAV", "newsList");
  *
  * // Lets say this is some other action
  * $this->removeBlock("newsList");
  *
  * </code>
  *
  * @param string $containerName Name of template variable to which content of this block will be assigned
  * @param string $blockName Name of block
  * @param string $viewName View name for block (without file extension)
  * @param bool $prepend Whether to add the block to the beginning of the current stack
  *
  * @see self::removeBlock()
  */
 public final function addBlock($containerName, $blockName, $viewName = null, $prepend = false)
 {
     if (!is_array($blockName)) {
         $blockName = array($this, $blockName);
     }
     $viewExt = $this->application->getRenderer()->getViewExtension();
     $blockMethodName = $blockName[1] . (substr($blockName[1], -5) == 'Block' ? '' : 'Block');
     if (empty($viewName)) {
         $viewName = "block" . DIRECTORY_SEPARATOR . $blockName[1] . "." . $viewExt;
     }
     $viewPath = $viewName . (substr($viewName, -1 * (strlen($viewExt) + 1)) == '.' . $viewExt ? '' : '.' . $viewExt);
     /*
     if (!method_exists($blockName[0], $blockMethodName))
     {
     	throw new ControllerException($this, "Block $blockName[1] not found!");
     }
     */
     $entry = array("container" => $containerName, "block" => $blockMethodName, "view" => $viewPath, 'call' => array($blockName[0], $blockMethodName));
     if ($prepend) {
         array_unshift($this->blockList, $entry);
     } else {
         $this->blockList[] = $entry;
     }
 }