本文整理汇总了PHP中comment::findByPage方法的典型用法代码示例。如果您正苦于以下问题:PHP comment::findByPage方法的具体用法?PHP comment::findByPage怎么用?PHP comment::findByPage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类comment
的用法示例。
在下文中一共展示了comment::findByPage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: comments
/**
* Render comment list.
*
* @return string
*/
public function comments()
{
$html = '';
$comments = comment::findByPage($this->page)->page(1, 10);
if ($comments->count() > 0) {
$html .= '<div class="items comments">';
foreach ($comments as $comment) {
$html .= tpl::load(__DIR__ . DS . 'template.php', array('field' => $this, 'comment' => $comment));
}
$html .= '</div>';
}
return $html;
}
示例2: comments
/**
* Retrieve all comments for the current page.
*
* @param string $page_uri Page uri.
* @param array $args Optional arguments.
*
* @return Comments
*/
function comments($page_uri = null, $args = array())
{
if (is_null($page_uri)) {
$page_uri = page()->uri();
}
// Customize query to perform
$defaults = array('walker' => null, 'echo' => true, 'author' => false, 'user' => false, 'order_by' => 'id', 'order' => 'DESC', 'unapproved' => true, 'page' => 1, 'per_page' => 20);
$args = array_merge($defaults, $args);
extract($args, EXTR_SKIP);
// Prepare query
$query = comment::findByPage($page_uri);
// Approved comments only
if ($unapproved === false) {
$query->andWhere('status', '=', Comment::STATUS_APPROVED);
}
// Specifc author only
if (!empty($author)) {
$query->andWhere('author', 'LIKE', $author);
} else {
if (!empty($user)) {
$user = $user instanceof User ? $user->username() : $user;
$query->andWhere('username', 'LIKE', $user);
}
}
// Order by clause
if (in_array($order_by, array('id', 'created_at', 'updated_at'))) {
$order = strtoupper($order) === 'DESC' ? $order : 'ASC';
$query->order($order_by . ' ' . $order);
}
// Perform query
$comments = $query->page($page, $per_page);
// Render comments if requested
if ($echo) {
$walker = !is_null($walker) ? new $walker() : new Comments\View\Walker();
$output = $walker->walk($comments);
echo $output;
}
return $comments;
}
示例3: findComments
/**
* Get all comments for a given page uri. Respects optional request parameter.
*
* @param string $uri Page uri
* @return Collection
*/
protected function findComments($uri)
{
// Take optional url paramaters into account
$page = get('page', 1);
$perPage = get('per_page', 30);
return comment::findByPage($uri)->page($page, $perPage);
}