本文整理汇总了PHP中Post::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::find方法的具体用法?PHP Post::find怎么用?PHP Post::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
function index()
{
$params = array('fields' => array('title', 'body', 'hoge'), 'order' => array('_id' => -1), 'limit' => 35, 'page' => 1);
$results = $this->Post->find('all', $params);
//$result = $this->Post->find('count', $params);
$this->set(compact('results'));
}
示例2: getArticle
public function getArticle($id)
{
$post = Post::find($id);
$sidePosts = Post::take(3)->offset(1)->orderby('id', 'desc')->get();
$comments = Comment::where('post_id', $id)->get();
return View::make('pages.view')->with(compact('post', 'sidePosts', 'comments'))->with('pageTitle', $post->title);
}
示例3: testCommentsReturnRelatedComments
public function testCommentsReturnRelatedComments()
{
$post1 = Post::find(1);
$post2 = Post::find(2);
$this->assertEquals(5, $post1->comments()->count());
$this->assertEquals(1, $post2->comments()->count());
}
示例4: edit
public function edit($id)
{
$post = Post::find($id);
$this->authorOrAdminPermissioinRequire($post->user_id);
$category_selects = Category::lists('name', 'id');
return View::make('posts.create_edit', compact('category_selects', 'post'));
}
示例5: articleAction
public function articleAction()
{
$posts = Post::find(['type = "post" AND id_web = "' . $this->auth->id_web . '" order by id desc']);
$paginator = new PaginatorModel(array("data" => $posts, "limit" => $this->params->limit, "page" => $this->params->page));
$page = $paginator->getPaginate();
$this->view->setVar("page", $page);
}
示例6: postContent
public function postContent($type_id, $id = 'add')
{
$all = Input::all();
if (!$all['slug']) {
$all['slug'] = BaseController::ru2Lat($all['title']);
}
$rules = array('name' => 'required|min:2|max:255', 'title' => 'required|min:3|max:255', 'slug' => 'required|min:4|max:255|alpha_dash');
$validator = Validator::make($all, $rules);
if ($validator->fails()) {
return Redirect::to('/admin/content/' . $type_id . '/' . $id)->withErrors($validator)->withInput()->with('error', 'Ошибка');
}
if (is_numeric($id)) {
$post = Post::find($id);
} else {
$post = new Post();
}
$post->type_id = $all['type_id'];
$post->name = $all['name'];
$post->title = $all['title'];
$post->slug = $all['slug'];
$post->text = $all['text'];
$post->parent = $all['parent'];
$post->status = isset($all['status']) ? true : false;
$post->order = $all['order'];
$post->description = $all['description'];
$post->keywords = $all['keywords'];
if (isset($all['image'])) {
$post->image = AdminController::saveImage($all['image'], 'upload/image/', 250);
}
$post->save();
return Redirect::to('/admin/content/' . $all['type_id'] . '/' . $id)->with('success', 'Изменения сохранены');
}
示例7: updatePost
public static function updatePost($input, $id)
{
$answer = [];
$rules = ['title' => 'required', 'body' => 'required', 'user_id' => 'required|integer'];
$validation = Validator::make($input, $rules);
if ($validation->fails()) {
$answer['message'] = $validation->errors()->getMessages();
$answer['error'] = true;
} else {
$post = Post::find($id);
$post->title = Input::get('title');
$post->image_url = Input::get('image_url');
$post->body = Input::get('body');
$post->user_id = Input::get('user_id');
if ($post->save()) {
$answer['message'] = 'Editado con exito!';
$answer['error'] = false;
$answer['data'] = $post;
} else {
$answer['message'] = 'UPDATE error, team noob!';
$answer['error'] = false;
}
}
return $answer;
}
示例8: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$post = Post::find($id);
$post->delete();
Session::flash('successMessage', 'Your post has been deleted.');
return Redirect::action('posts.index');
}
示例9: testTranslatedAttributesCanBeRetrievedInDifferentLocales
public function testTranslatedAttributesCanBeRetrievedInDifferentLocales()
{
$this->createTwoPostsWithOneTranslatedInThreeLocales();
$model = Post::find(1);
$model->translations()->where('locale', 'en')->update(['title' => 'New Title']);
$this->assertEquals('New Title', Post::find(1)->title);
}
示例10: testPostKeywords
public function testPostKeywords()
{
$post = Post::find(16);
$this->assertTrue(count($post->keywords) > 0);
$post = Post::find(2);
$this->assertTrue(count($post->keywords) == 0);
}
示例11: delete
public function delete($id)
{
$post = $this->blogRepository->find($id);
// Title
$title = Lang::get('admin.blogs.title.blog_delete');
// Show the page
$this->render('admin.blogs.delete', compact('post', 'title'));
}
示例12: show
public function show($id)
{
$post = Post::find($id);
if ($post->is_premium && Auth::user()->stripe_plan != 'gold') {
return View::make('error', ['message' => 'Only GOLD members can read this post, <a href="/upgrade">upgrade</a> your membership to get access']);
}
return View::make('post', ['post' => $post]);
}
示例13: testModelCanBeMassUpdated
public function testModelCanBeMassUpdated()
{
Post::forceCreate(['id' => 1, 'title' => 'Lorem ipsum']);
Post::forceCreate(['id' => 2, 'title' => 'Lorem ipsum']);
Post::where('title', 'Lorem ipsum')->update(['title' => 'Lorem ipsum 2']);
$this->assertEquals('Lorem ipsum 2', Post::find(1)->title);
$this->assertEquals('Lorem ipsum 2', Post::find(2)->title);
}
示例14: getComments
private function getComments()
{
$post = Post::find(Input::get('post'));
if (is_null($post)) {
return false;
}
return $post->comments()->where('created_at', '>', Input::get('timestamp'))->take($this->count)->get();
}
示例15: setPostId
/**
* MI: Warning for Windows:
* The PHP function symlink only works on Windows Vista, Server 2008 or greater.
*/
public function setPostId($id)
{
$post = Post::find($id);
$file = $post->file_path();
symlink($file, $this->tempfile_image_path());
$this->received_file = true;
$this->md5 = $post->md5;
}