阅读本文并完成装饰器示例。代码返回<strong></strong>
而不是预期的<strong><a href="logout.php">Logout</a></strong>
。
class HtmlLinks {
//some methods which is available to all html links
}
class LogoutLink extends HtmlLinks
{
protected $_html;
public function __construct() {
$this->_html = "<a href=\"logout.php\">Logout</a>";
}
public function setHtml($html) {
$this->_html = $html;
}
public function render() {
echo $this->_html;
}
}
class LogoutLinkStrongDecorator extends HtmlLinks {
protected $_logout_link;
public function __construct( $logout_link ) {
$this->_logout_link = $logout_link;
$this->setHtml("<strong>" . $this->_html . "</strong>");
}
public function __call( $name, $args ) {
$this->_logout_link->$name($args[0]);
}
}
$logout_link = new LogoutLink();
$logout_link = new LogoutLinkStrongDecorator($logout_link);
$logout_link->render();
整个下午都试图调试,但我没有取得任何进展。任何见解将不胜感激。