当然,我正在尝试将我的网站移至 Hack 和 XHP。下面是我想要实现的代码结构的结构:
<ui:backstageHeader>
<ui:backstageHeader-navItem href="/">stories</ui:backstageHeader-navItem>
<ui:backstageHeader-navItem href="/story/send">send a story</ui:backstageHeader-navItem>
<ui:backstageHeader-navItem href="/aboutus">support</ui:backstageHeader-navItem>
</ui:backstageHeader>
(注意: :ui:backstageHeader-navItem
基本上渲染到<a href={$this->:href}>{$this->getCHildren}</a>
所以这里不需要附加它的类。)
下面是代码:ui:backstageHeader
:
final class :ui:backstageHeader extends :ui:base {
attribute :div;
children (:ui:backstageHeader-navItem)*;
protected function compose() {
$dom =
<section class="backstage-header">
<div class="container">
<div class="cell-logo">
<a href="/">
<span class="no23-logo-white"></span>
</a>
</div>
<div class="cell-navigation">
</div>
<div class="cell-account">
<div class="cell-login">
<div id="siteNav-login">Autentificare</div>
</div>
</div>
</div>
</section>;
$mainContainer = $dom->getChildren("div")[0];
$cellNavigation = $mainContainer->getChildren("div")[1];
$navItems = <ul class="main-navigation"></ul>;
foreach($this->getChildren() as $child) {
$navItems->appendChild(<li>{$child}</li>);
}
$dom->appendChild($navItems);
return $dom;
}
}
我使用终端来调试我的代码hhvm -m d <file.php>
,一切都很好;但是,当我访问我的浏览器时,我得到了500
错误标题。这就是日志所说的:
Catchable fatal error: Hack type error: Could not find method getChildren in an object of type XHPChild at /var/www/res/ui/backstage-header.php line 25
错误来自
$cellNavigation = $mainContainer->getChildren("div")[1];
但是,不知何故,我需要ul.main-navigation
从div.cell-navigation
我的section.backstage-header
.
我该怎么做?