public setTemplate ( string $tmpl ) : |
||
$tmpl | string | |
Результат |
public function setTemplate($tmpl)
{
if (preg_match('/(.*)\\.(x|ht|pht|xht)ml/i', $tmpl) || substr($tmpl, -4) == '.htm' || substr($tmpl, -4) == '.php' || substr($tmpl, -5) == '.php3' || substr($tmpl, -4) == '.txt') {
if (file_exists($tmpl)) {
$this->template = stripos($tmpl, '.phtml') === false && stripos($tmpl, '.php') === false ? file_get_contents($tmpl) : $tmpl;
} else {
$this->template = $tmpl;
}
} else {
$this->template = $tmpl;
}
return $this;
}
public function testRenderWithTemplate() { $e = new Element('text', 'username', 'Username'); $e->setLabel('Username'); $s = new Element('submit', 'submit', 'Submit'); $f = new Form('/submit', 'post'); $f->addElements(array($e, $s)); $f->setTemplate("[{username}] [{submit}]"); $f->username = '******'; $form = $f->render(true); $this->assertContains('<form ', $form); $this->assertEquals('My Username', $f->username); }