本文整理汇总了PHP中Forum::as_array方法的典型用法代码示例。如果您正苦于以下问题:PHP Forum::as_array方法的具体用法?PHP Forum::as_array怎么用?PHP Forum::as_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Forum
的用法示例。
在下文中一共展示了Forum::as_array方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forum
/**
* Forums list
*
* @param Request $request
* @param null $matches
* @return mixed
*/
public function forum(Request $request, $matches = null)
{
$forums_list = \Forum::find('all', ['conditions' => ['forum_id < 1']]);
// Make array and get child subjects
$forums_list = \Forum::as_array($forums_list);
$forums_list = array_map(function ($item) {
$item['subjects'] = \Forum::as_array(\Forum::find('all', ['conditions' => ['forum_id = ?', $item['id']]]));
return $item;
}, $forums_list);
return $this->view->render('forum/forum.twig', ['title' => $this->lang->translate('forum.title'), 'forums_list' => $forums_list]);
}
示例2: edit_topic
public function edit_topic(Request $request, $matches)
{
$title = $this->lang->translate('forum.create');
// Get page for updating
$id = intval($matches->get('id', $request->get('id')));
// Parent topic
$topics = \Forum::as_array(\Forum::find('all', ['conditions' => ['forum_id = 0 AND id <> ?', $id]]));
if ($id > 0) {
$forum = \Forum::find_by_id($id);
$title = $this->lang->translate('forum.editing', $forum->title);
} else {
$forum = ['title' => $this->lang->translate('page.name'), 'forum_id' => null];
}
// Create or update page
if ($request->isMethod('post')) {
if ($forum instanceof \Forum) {
$forum->title = $request->get('title');
$forum->forum_id = $request->get('forum');
$forum->author_id = $this->user->id;
} else {
$forum = new \Forum(['title' => $request->get('title'), 'forum_id' => $request->get('forum'), 'author_id' => $this->user->id]);
}
// Updating instance
$forum->save();
$forum = $forum->to_array();
return static::json_response(['success' => true, 'message' => $this->lang->translate('form.saved')]);
}
return $this->view->render('forum/create.twig', ['forum' => $forum, 'title' => $title, 'topics' => $topics]);
}