本文整理汇总了PHP中News::find_by_id方法的典型用法代码示例。如果您正苦于以下问题:PHP News::find_by_id方法的具体用法?PHP News::find_by_id怎么用?PHP News::find_by_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类News
的用法示例。
在下文中一共展示了News::find_by_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($id = null)
{
$tag = self::load_tag($id);
$this->assign("tag", $tag);
$page = 1;
if (isset($_GET['page'])) {
$page = $_GET['page'];
}
$tag_id = mysql_real_escape_string($tag->id);
$news = NewsTag::paginate("tags.id = '{$tag_id}'", $page, 10);
$items = array();
foreach ($news->collection as $newsitem) {
$items[] = News::find_by_id($newsitem->news->id);
}
$news->collection = $items;
$this->assign("page", $news);
$this->title = "View Tag";
$this->render("tag/show.tpl");
}
示例2: createComment
/**
* Создание комментария
*/
public function createComment($id)
{
if (!($news = News::find_by_id($id))) {
App::abort('default', 'Данной новости не существует!');
}
$comment = new Comment();
$comment->token = Request::input('token', true);
$comment->user_id = User::get('id');
$comment->relate_type = 'News';
$comment->relate_id = $news->id;
$comment->text = Request::input('text');
$comment->ip = App::getClientIp();
$comment->brow = App::getUserAgent();
if ($comment->save()) {
App::setFlash('success', 'Сообщение успешно добавлено!');
} else {
App::setFlash('danger', $comment->getErrors());
App::setInput($_POST);
}
App::redirect('/news/' . $id);
}
示例3: tags
public function tags($tag = null)
{
$tag = self::load_tag($tag);
$page = 1;
if (isset($_GET['page'])) {
$page = $_GET['page'];
}
$tag_id = mysql_real_escape_string($tag->id);
$news = NewsTag::paginate("tags.id = '{$tag_id}' AND news.published = true AND news.publish_at < NOW()", "news.publish_at DESC", $page, 10);
$items = array();
foreach ($news->collection as $newsitem) {
$item = News::find_by_id($newsitem->news->id);
if (!$item) {
continue;
}
$items[] = $item;
}
$news->collection = $items;
$this->assign("page", $news);
$this->assign("tag", $tag);
$this->title = "News :: {$tag->tag}";
$this->render("news/tags.tpl");
}