本文整理汇总了PHP中api::createPageNum方法的典型用法代码示例。如果您正苦于以下问题:PHP api::createPageNum方法的具体用法?PHP api::createPageNum怎么用?PHP api::createPageNum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api
的用法示例。
在下文中一共展示了api::createPageNum方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sort
public function sort($id = '')
{
$page = $this->page($id);
$blueprint = blueprint::find($page);
$uids = get('uids');
$flip = $blueprint->pages()->sort() == 'flip';
$children = $page->children();
if ($flip) {
$index = get('index', 1);
$uids = array_reverse($uids);
$n = $page->children()->visible()->count() - ($index * $blueprint->pages()->limit() - 1);
if ($n <= 0) {
$n = 1;
}
} else {
$index = get('index', 1) - 1;
$n = $blueprint->pages()->limit() * $index + 1;
}
foreach ($uids as $uid) {
try {
$child = $children->find($uid);
$x = api::createPageNum($child, $blueprint);
if ($x !== false and $x >= 0) {
$child->sort($x);
} else {
$child->sort($n);
}
$n++;
} catch (Exception $e) {
}
}
return response::success('success');
}
示例2: update
public function update($id = '')
{
$page = $this->page($id);
if (!$page) {
return response::error(l('pages.error.missing'));
}
$blueprint = blueprint::find($page);
$fields = $blueprint->fields($page);
$oldTitle = (string) $page->title();
// trigger the validation
$form = new Form($fields->toArray());
$form->validate();
// fetch the data for the form
$data = pagedata::createByInput($page, $form->serialize());
// stop at invalid fields
if (!$form->isValid()) {
return response::error(l('pages.show.error.form'), 400, array('fields' => $form->fields()->filterBy('error', true)->pluck('name')));
}
try {
PageStore::discard($page);
$page->update($data);
// make sure that the sorting number is correct
if ($page->isVisible()) {
$num = api::createPageNum($page);
if ($num !== $page->num()) {
if ($num > 0) {
$page->sort($num);
}
}
}
// get the blueprint of the parent page to find the
// correct sorting mode for this page
$parentBlueprint = blueprint::find($page->parent());
// auto-update the uid if the sorting mode is set to zero
if ($parentBlueprint->pages()->num()->mode() == 'zero') {
$uid = str::slug($page->title());
$page->move($uid);
}
history::visit($page->id());
kirby()->trigger('panel.page.update', $page);
return response::success('success', array('file' => $page->content()->root(), 'data' => $data, 'uid' => $page->uid(), 'uri' => $page->id()));
} catch (Exception $e) {
return response::error($e->getMessage());
}
}