本文整理汇总了PHP中News::find方法的典型用法代码示例。如果您正苦于以下问题:PHP News::find方法的具体用法?PHP News::find怎么用?PHP News::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类News
的用法示例。
在下文中一共展示了News::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: news_show
function news_show()
{
global $news_show;
$news = new News();
$news_show = $news->find($_GET['id']);
render();
}
示例2: removeNews
public function removeNews($id)
{
$news = News::find($id);
$name = $news->title;
$news->delete();
return Redirect::route('account')->with('status', 'alert-success')->with('global', 'You just deleted ' . $name);
}
示例3: togglePublish
/**
* @param $id
* @return mixed
*/
public function togglePublish($id)
{
$news = $this->news->find($id);
$news->is_published = $news->is_published ? false : true;
$news->save();
return Response::json(array('result' => 'success', 'changed' => $news->is_published ? 1 : 0));
}
示例4: Insert_UpdateNews
public function Insert_UpdateNews($data)
{
$id = Input::get("id");
if (!Input::has('id')) {
$news = new News();
} else {
$news = News::find(array_get($data, 'id'));
//tìm id đã có trong data
}
$news->title = array_get($data, 'title');
// Upload images
if (Input::file('file')) {
define('PATH_CATEGORY_ICON', rtrim($_SERVER['DOCUMENT_ROOT'], '/') . '/upload/');
$file = array_get($data, 'file');
$file->move(PATH_CATEGORY_ICON, $file->getClientOriginalName());
$news->images = $file->getClientOriginalName();
}
// End Upload images
$news->tomtat = array_get($data, 'tomtat');
$news->content = array_get($data, 'content');
$news->cat_id = array_get($data, 'cat_id');
$news->hot = array_get($data, 'hot');
$news->ngaydangbai = date('Y-m-d H:i:s');
return $news->save();
}
示例5: listAction
public function listAction()
{
$params = $this->request->getQuery();
if ($params['_url'] != null) {
$string = ltrim($params['_url'], '/danh-muc');
}
$array = explode('-', $string);
$id = $array[0];
// Get name category
$category = Category::findFirstById($id);
$this->tag->setTitle($category->name);
// Get list category of id
if ($id != '' && $id > 0) {
// The data set to paginate
$news = News::find(array('active = 1 AND category =' . $id, 'order' => 'id DESC'));
$currentPage = (int) $_GET["page"];
// Create a Model paginator, show 10 rows by page starting from $currentPage
$paginator = new PaginatorModel(array("data" => $news, "limit" => 13, "page" => $currentPage));
// Get the paginated results
$page = $paginator->getPaginate();
$this->view->setVar('page', $page);
$this->view->setVar('category', $category);
} else {
$this->response->redirect('error');
}
}
示例6: testEmpty
public function testEmpty()
{
$news = News::find();
$this->assertTrue($news->count() == 0);
$news = new News();
$news->title = "A new News!";
$this->assertFalse($news->save());
}
示例7: showYearAction
public function showYearAction()
{
$activeYear = $this->filter->sanitize($this->_getParam('year'), "int");
Phalcon_Tag::setTitle('News');
$this->view->setVar("news", News::find(array("year='{$activeYear}'", "order" => "published DESC")));
$this->view->setVar("activeYear", $activeYear);
$this->view->setVar("years", News::count(array('group' => 'year')));
}
示例8: get_detail
public function get_detail($id)
{
$news = News::find($id);
if (is_null($news)) {
return json_encode('News not found', 404);
} else {
return json_encode($news);
}
}
示例9: hasUpdated
public function hasUpdated()
{
$checksum = News::find()->select('SUM(`publishDate`)')->where(['or', ['in', 'categoryID', $this->categories], ['in', 'id', $this->articles]])->scalar();
if (\Yii::$app->cache->get('rssfeed-' . $this->id . '-checksum') != $checksum) {
\Yii::$app->cache->set('rssfeed-' . $this->id . '-checksum', $checksum);
return true;
}
return false;
}
示例10: post_delete
public function post_delete($id)
{
$news = News::find($id);
if (empty($news)) {
return View::make('msg.error')->with('error', 'That news item doesn\'t exist.');
}
$news->delete();
return Redirect::to('/admin/news/overview');
}
示例11: get_delete
public function get_delete($id = false)
{
if (!$id) {
return Redirect::to('news');
}
$news = News::find($id);
$news->delete();
return Redirect::to('news');
}
示例12: indexAction
public function indexAction()
{
$language = Phalcon_Session::get('language');
$news = News::find(array("language='{$language}'", "limit" => 5, "order" => "published desc"));
if (count($news) === 0) {
$news = News::find(array("language='en'", "limit" => 5, "order" => "published desc"));
}
//Query the last 5 news
$this->view->setVar("news", $news);
}
示例13: destroy
public function destroy($id, $request)
{
$data = ['success' => false];
if (News::exists($id)) {
$new = News::find($id);
if ($new->belongsToUser(Session::get())) {
$data['success'] = $new->delete();
}
}
return new JsonResponse($data);
}
示例14: index
function index() {
$recent_events = Event::find()->where(array('created_at >= NOW() - INTERVAL 1 WEEK'))->order('created_at DESC')->all();
$find_news = News::find()
->order(array('weight ASC', 'updated_at DESC'))
->limit(5);
$this->render(array(
'recent_events' => $recent_events,
'news' => $find_news->all(),
));
}
示例15: showSinglePressItem
public function showSinglePressItem($slug, $id)
{
$pressItem = News::with('catalog')->find($id);
if (!$pressItem || !$pressItem->isActive() || $pressItem->getSlug() != $slug) {
App::abort(404);
}
$previousPressItemId = News::active()->where('id', '<', $pressItem->id)->max('id');
$previousPressItem = News::find($previousPressItemId);
$nextPressItemId = News::active()->where('id', '>', $pressItem->id)->min('id');
$nextPressItem = News::find($nextPressItemId);
return View::make('about.press.single', compact('pressItem', 'previousPressItem', 'nextPressItem'));
}