Pop\Form\Element::render PHP Method

render() public method

Method to render the child and its child nodes.
public render ( boolean $ret = false, integer $depth, string $indent = null, string $errorIndent = null ) : string
$ret boolean
$depth integer
$indent string
$errorIndent string
return string
    public function render($ret = false, $depth = 0, $indent = null, $errorIndent = null)
    {
        $output = parent::render(true, $depth, $indent);
        $errors = null;
        $container = $this->errorDisplay['container'];
        $attribs = null;
        foreach ($this->errorDisplay['attributes'] as $a => $v) {
            $attribs .= ' ' . $a . '="' . $v . '"';
        }
        // Add error messages if there are any.
        if (count($this->errors) > 0) {
            foreach ($this->errors as $msg) {
                if ($this->errorDisplay['pre']) {
                    $errors .= "{$indent}{$this->indent}<" . $container . $attribs . ">{$msg}</" . $container . ">\n{$errorIndent}";
                } else {
                    $errors .= "{$errorIndent}{$indent}{$this->indent}<" . $container . $attribs . ">{$msg}</" . $container . ">\n";
                }
            }
        }
        $output = $this->errorDisplay['pre'] ? $errors . $output : $output . $errors;
        return $output;
    }

Usage Example

コード例 #1
0
ファイル: ElementTest.php プロジェクト: nicksagona/PopPHP
 public function testRender()
 {
     $e = new Element('text', 'email');
     $element = $e->render(true);
     $e->setErrorPre(true);
     $element = $e->render(true);
     ob_start();
     $e->output();
     $output = ob_get_clean();
     $this->assertContains('<input', $element);
     $this->assertContains('<input', $output);
 }