Created
May 13, 2013 05:46
-
-
Save miszmaniac/5566377 to your computer and use it in GitHub Desktop.
Próbka - jak można użyć Traitów w widokach.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
trait FormElements { | |
protected function getLabel($text, $for) { | |
return "<label for='$for'>$text</label>"; | |
} | |
protected function getTextInput($name) { | |
return "<input type='text' name='$name'/>"; | |
} | |
} | |
trait FormDecorator { | |
use FormElements; | |
protected function getLabeledInput($name) { | |
$asciiName = iconv('utf-8', 'ascii//translit//ignore', $name); | |
$label = $this->getLabel($name, $asciiName); | |
$input = $this->getTextInput($asciiName); | |
return "<dt>$label</dt><dd>$input</dd>"; | |
} | |
protected function decorateForm($form) { | |
return "<dl>$form</dl>"; | |
} | |
} | |
class HtmlForm { | |
use FormDecorator; | |
public function createLoginForm() { | |
$form = $this->getLabeledInput('user') . $this->getLabeledInput('email'). $this->getLabeledInput('password'); | |
return $this->decorateForm($form); | |
} | |
} | |
$form = new HtmlForm(); | |
echo $form->createLoginForm(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment