本文整理汇总了PHP中app\models\Post::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::find方法的具体用法?PHP Post::find怎么用?PHP Post::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
public function update($id, UpdatePostRequest $request)
{
$post = Post::find($id);
$post->post = $request->get('post');
$post->save();
return redirect()->route('posts.show', $post->id)->with('successes', ['Post updated successfully']);
}
示例2: postsAndGrants
public function postsAndGrants()
{
$id = $this->request->query['id'];
// First find all posts for group
$posts = Post::find('all', array('conditions' => array('groupId' => new \MongoId($id)), 'limit' => 10))->to('array');
$ids = array();
$total = 0;
foreach ($posts as &$p) {
$total += $p['y2011'];
/*
$post = $p['post'];
$ids[] = $post;
*/
}
/*
$grants = Grant::find('all', array(
'conditions' => array(
'post' => array(
'$in' => $ids
)
),
'limit' => 100
))->to('array');
*/
return compact('total', 'posts');
}
示例3: __init
public static function __init(array $options = array())
{
parent::__init($options);
$self = static::_instance();
$self->_finders['count'] = function ($self, $params, $chain) use(&$query, &$classes) {
$db = Connections::get($self::meta('connection'));
$records = $db->read('SELECT count(*) as count FROM posts', array('return' => 'array'));
return $records[0]['count'];
};
Post::applyFilter('save', function ($self, $params, $chain) {
$post = $params['record'];
if (!$post->id) {
$post->created = date('Y-m-d H:i:s');
} else {
$post->modified = date('Y-m-d H:i:s');
}
$params['record'] = $post;
return $chain->next($self, $params, $chain);
});
Validator::add('isUniqueTitle', function ($value, $format, $options) {
$conditions = array('title' => $value);
// If editing the post, skip the current psot
if (isset($options['values']['id'])) {
$conditions[] = 'id != ' . $options['values']['id'];
}
// Lookup for posts with same title
return !Post::find('first', array('conditions' => $conditions));
});
}
示例4: actionIndex
public function actionIndex()
{
$query = Post::find();
$pagination = new Pagination(['defaultPageSize' => 6, 'totalCount' => $query->count()]);
$posts = $query->offset($pagination->offset)->limit($pagination->limit)->all();
return $this->render('index', ['posts' => $posts, 'pagination' => $pagination]);
}
示例5: love
function love(array $params)
{
$response = new ResponseEntity();
DB::transaction(function () use(&$response, $params) {
if ($params['postId']) {
$ep = Post::find($params['postId']);
if (!$ep) {
$response->setMessages(['Post is not available']);
} else {
$p = new PostLove();
$p->post_id = $params['postId'];
$p->user_id = Auth::user()->id;
$ok = $p->save();
if ($ok) {
$response->setSuccess(true);
} else {
$response->setMessages(['Something went wrong!']);
}
}
} else {
$response->setMessages(['Post is not available']);
}
});
return $response;
}
示例6: actionIndex
/**
* Lists all Post models.
* @return mixed
*/
public function actionIndex()
{
$request = Yii::$app->request;
$page_id = $request->get('page_id');
$search = $request->get('search');
$columns = Page::find()->where(['type' => 3])->all();
if ($search) {
$query = Post::find()->where(['like', 'name', $search])->orWhere(['like', 'content', $search]);
$countQuery = clone $query;
$pnation = new Pagination(['defaultPageSize' => 10, 'totalCount' => $countQuery->count()]);
$post = $query->orderBy(['create_date' => SORT_DESC])->offset($pnation->offset)->limit($pnation->limit)->all();
return $this->render('index', ['page_id' => $page_id, 'pnation' => $pnation, 'post' => $post, 'columns' => $columns]);
}
if ($page_id) {
$query = Post::find()->where(['page_id' => $page_id]);
$countQuery = clone $query;
$pnation = new Pagination(['defaultPageSize' => 10, 'totalCount' => $countQuery->count()]);
$post = $query->orderBy(['create_date' => SORT_DESC])->offset($pnation->offset)->limit($pnation->limit)->all();
} else {
$query = Post::find();
$countQuery = clone $query;
$pnation = new Pagination(['defaultPageSize' => 10, 'totalCount' => $countQuery->count()]);
$post = $query->orderBy(['create_date' => SORT_DESC])->offset($pnation->offset)->limit($pnation->limit)->all();
}
return $this->render('index', ['page_id' => $page_id, 'pnation' => $pnation, 'post' => $post, 'columns' => $columns]);
}
示例7: generateFeed
/**
* @param ATOM|RSS2 $feed
* @return ATOM|RSS2
*/
protected function generateFeed($feed)
{
/* @var Post[] $posts */
$site_name = ArrayHelper::getValue(Yii::$app->params, 'site_name', Yii::$app->name);
$posts = Post::find()->where(['status' => Post::STATUS_PUBLISHED])->orderBy(['post_time' => SORT_DESC, 'update_time' => SORT_DESC])->limit(20)->all();
$feed->setTitle($site_name);
$feed->setLink(Url::home(true));
$feed->setSelfLink(Url::to(['feed/rss'], true));
$feed->setAtomLink(Url::to(['feed/atom'], true));
$feed->setDescription(ArrayHelper::getValue(Yii::$app->params, 'seo_description', '最新更新的文章'));
if ($posts) {
$feed->setDate($posts[0]->update_time);
} else {
$feed->setDate(time());
}
foreach ($posts as $post) {
$entry = $feed->createNewItem();
$entry->setTitle($post->title);
$entry->setLink($post->getUrl(true));
$entry->setDate(intval($post->post_time));
$entry->setDescription($post->excerpt);
$entry->setAuthor($post->author_name ? $post->author_name : $post->author->nickname);
$entry->setId($post->alias);
if ($feed instanceof ATOM) {
$entry->setContent($post->content);
}
$feed->addItem($entry);
}
return $feed;
}
示例8: actionIndex
/**
* Lists all Post models.
* @return mixed
*/
public function actionIndex()
{
$dataProvider = Post::find();
$pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $dataProvider->count()]);
$posts = $dataProvider->offset($pagination->offset)->limit($pagination->limit)->all();
return $this->render('index', ['posts' => $posts, 'pagination' => $pagination, 'category' => Category::find()->all(), 'comment_list' => Comment::find()->all()]);
}
示例9: run
public function run()
{
$post = Post::find(1);
$post->categories()->attach([13]);
$post = Post::find(2);
$post->categories()->attach([15]);
$post = Post::find(3);
$post->categories()->attach([22]);
$post = Post::find(4);
$post->categories()->attach([5, 24]);
$post = Post::find(5);
$post->categories()->attach([4, 12]);
$post = Post::find(6);
$post->categories()->attach([10]);
$post = Post::find(7);
$post->categories()->attach([4, 12]);
$post = Post::find(8);
$post->categories()->attach([18]);
$post = Post::find(9);
$post->categories()->attach([3, 4, 12]);
$post = Post::find(10);
$post->categories()->attach([5]);
$post = Post::find(11);
$post->categories()->attach([5]);
$post = Post::find(12);
$post->categories()->attach([18]);
}
示例10: destroy
function destroy($id)
{
$post = \App\Models\Post::find($id);
unlink(public_path($post->imagens));
unlink(public_path($post->imagenl));
$post->delete();
return redirect('posts');
}
示例11: story
public function story(Request $request, $id)
{
$post = Post::find($id);
if (!$post) {
return redirect('/');
}
return view('posts.view', array('post' => $post));
}
示例12: view
public function view(Request $request, $id = '')
{
$model = \App\Models\Post::find($id);
if (!is_null($model)) {
return view('post.view', ['model' => $model]);
}
return response()->view('errors.404', array(), 404);
}
示例13: postdetail
/**
* [postdetail description]
* @param [type] $post_id [description]
* @return [type] [description]
*/
public function postdetail($post_id)
{
$post = Post::find($post_id);
$post->category = Category::find($post->category_id);
$randomposts = Post::getRandomPost();
$postfeatures = Post::getPostFeaturedWidget();
$commentposts = Comment::getCommentByPostId($post_id);
return view('home.detailpost', compact('post', 'randomposts', 'postfeatures', 'commentposts'));
}
示例14: sendPost
public static function sendPost($id, $ticket_updated, $request)
{
$post = Post::find($id);
$emails = array();
if ($request) {
foreach ($request as $key => $target) {
switch ($key) {
case 'account_manager':
if ($target == 'true') {
$emails[] = $post->ticket->company->account_manager->company_person->email;
}
break;
case 'company_group_email':
if ($target == 'true') {
$emails[] = $post->ticket->company->group_email;
}
break;
case 'company_contact':
if ($target == 'true') {
$emails[] = $post->ticket->contact->email;
}
break;
case 'ticket_emails':
if ($target == 'true') {
$emails = array_merge($emails, explode(",", $post->ticket->emails));
}
break;
default:
break;
}
}
}
$emails[] = $post->ticket->assignee->email;
foreach ($emails as $email) {
self::add('to', $email);
}
switch ($post->ticket->division->id) {
case LGV_DIVISION_ID:
self::add("cc", self::LGV_TEAM_LEADER_EMAIL);
break;
case PC_DIVISION_ID:
self::add("cc", self::PC_TEAM_LEADER_EMAIL);
break;
case PLC_DIVISION_ID:
self::add("cc", self::PLC_TEAM_LEADER_EMAIL);
break;
default:
break;
}
self::setSubject("New Post | Ticket #" . $post->ticket->id . " | " . $post->author->person->name());
self::$view = "emails/post";
self::$data['post'] = $post;
self::$data['title'] = "New Post for Ticket #" . $post->ticket->id;
self::$data['ticket_updated'] = $ticket_updated;
self::send();
Activity::log("Email Post Send", self::$data);
}
示例15: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$post = Post::find($id);
if (!$post) {
return $this->respondNotFound('Post Not Found');
}
$data = fractal()->item($post)->transformWith(new PostTransformer())->includeUser()->includeCategories()->toArray();
return $this->respond($data);
}