本文整理匯總了PHP中HtmlObject\Element::setParent方法的典型用法代碼示例。如果您正苦於以下問題:PHP Element::setParent方法的具體用法?PHP Element::setParent怎麽用?PHP Element::setParent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類HtmlObject\Element
的用法示例。
在下文中一共展示了Element::setParent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: insertChildAtPosition
/**
* Prepend or append to self/child.
*
* @param Element $child
* @param string $name
* @param null $subject
* @param null $position
* @param boolean $before
*
* @return $this
*/
protected function insertChildAtPosition($child, $name = null, $subject = null, $position = null, $before = false)
{
// Get default child name
$subject = $subject ?: $this;
$name = $name ?: count($this->children);
// Bind parent to child
if ($child instanceof TreeObject) {
$child->setParent($subject);
}
// Add object to children
$child->parentIndex = $name;
// If the position is a child name, get its index
$before = $before ? 0 : 1;
$position = is_null($position) ? count($subject->children) : $position;
if (is_string($position)) {
$position = array_search($position, array_keys($subject->children));
}
if (is_string($name) && isset($subject->children[$name])) {
$subject->children[$name] = $child;
return $this;
}
// Slice and recompose children
$subject->children = array_slice($subject->children, 0, $position + $before, true) + array($name => $child) + array_slice($subject->children, $position, count($subject->children), true);
return $this;
}