Example #1
0
 /**
  * @param string $filename
  * @param array $param
  * @param array $headers
  * @return bool
  * @throws PMPException
  */
 public function rendar($filename, $param = array(), $headers = array())
 {
     try {
         $this->rendarParamSet();
         // set template
         $this->template->assign_vars($param);
         // default file
         foreach ($this->default_templatefiles as $file) {
             $template = new \PMP\Template();
             if ($template->load($file)) {
                 $template->setBlockData();
                 foreach ($template->getBlocks() as $key => $val) {
                     $this->template->setBlock($key, $val);
                 }
             }
         }
         // load template
         if ($this->template->load($this->path . '/view/' . $filename)) {
             $html = $this->template->get_display_template(true);
             return $this->rendarString($html, $headers);
         } else {
             throw new PMPException('File Not Found(`' . $this->path . '/view/' . $filename . '`).');
         }
     } catch (PMPException $e) {
         $e->displayError();
         return false;
     }
     return true;
 }
Example #2
0
use PMP\htmlElement;
/**
 * init framework file
 */
PMP\Template::filter('html_element', function (htmlElement $element, $param = array()) {
    foreach ($param as $key => $val) {
        $element->addAttr($key, $val);
    }
    return $element;
});
/**
 * routing
 */
PMP\Template::filter("path", function () {
    $routing = new \PMP\Routing();
    return call_user_func_array(array($routing, 'getUrl'), func_get_args());
});
/**
 * form template function
 */
\PMP\Template::filter('form_start', function (\PMP\Template $template, $form, $options) {
    $template->getCurrentNode()->setModifierFlag(true);
    if ($form instanceof \PMP\FormView) {
        $params = array_merge(array('action' => $form->getFormActionUrl(), 'method' => 'POST'), $options);
        $attr = array();
        foreach ($params as $key => $val) {
            $attr[$key] = $val;
        }
        $attr_tag = array();
        foreach ($attr as $key => $val) {
            $attr_tag[] = ' ' . $key . '="' . $val . '"';