render() public method

Method to render the document and its child elements.
public render ( boolean $ret = false ) : mixed
$ret boolean
return mixed
示例#1
0
 public function testRender()
 {
     $d = new Dom(Dom::XHTML11, 'utf-8', new Child('p', 'This is another paragraph'));
     $d->addChild(new Child('p', 'This is a paragraph'));
     $code = $d->render(true);
     ob_start();
     $d->render();
     $output = ob_get_clean();
     $this->assertContains('<p>', $code);
     $this->assertContains('<p>', $output);
 }
示例#2
0
文件: dom.php 项目: nicksagona/PopPHP
<?php

require_once '../../bootstrap.php';
use Pop\Dom\Child;
use Pop\Dom\Dom;
try {
    $title = new Child('title', 'This is the title');
    $meta = new Child('meta');
    $meta->setAttributes(array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8'));
    $head = new Child('head');
    $head->addChildren(array($title, $meta));
    $h1 = new Child('h1', 'This is a header');
    $p = new Child('p', 'This is a paragraph.');
    $div = new Child('div');
    $div->setAttributes('id', 'contentDiv');
    $div->addChildren(array($h1, $p));
    $body = new Child('body');
    $body->addChild($div);
    $html = new Child('html');
    $html->setAttributes(array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => 'en'));
    $html->addChildren(array($head, $body));
    $doc = new Dom(Dom::XHTML11, 'utf-8', $html);
    $doc->render();
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
示例#3
0
 /**
  * Method to render the feed and its items
  *
  * @param  boolean $ret
  * @return mixed
  */
 public function render($ret = false)
 {
     if ($this->feedType == Writer::JSON || $this->feedType == Writer::PHP) {
         $this->output = null;
         if ($this->feedType == Writer::JSON) {
             $this->output = json_encode($this->data);
         } else {
             if ($this->feedType == Writer::PHP) {
                 $this->output = serialize($this->data);
             }
         }
         if ($ret) {
             return $this->output;
         } else {
             if (!headers_sent()) {
                 header("HTTP/1.1 200 OK");
                 header("Content-type: " . $this->contentType);
             }
             echo $this->output;
         }
     } else {
         return parent::render($ret);
     }
 }