本文整理汇总了PHP中Posts::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Posts::find方法的具体用法?PHP Posts::find怎么用?PHP Posts::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Posts
的用法示例。
在下文中一共展示了Posts::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
public function edit($id)
{
// find article
if (($article = Posts::find(array('id' => $id))) === false) {
return Response::redirect($this->admin_url . '/posts');
}
// process post request
if (Input::method() == 'POST') {
if (Posts::update($id)) {
// redirect path
return Response::redirect($this->admin_url . '/posts/edit/' . $id);
}
}
// get comments
$comments = Comments::list_all(array('post' => $id));
$pending = array();
foreach ($comments as $comment) {
if ($comment->status == 'pending') {
$pending[] = $comment->id;
}
}
$pending = count($pending);
// get posts page
$page = Pages::find(array('id' => Config::get('metadata.posts_page')));
Template::render('posts/edit', array('article' => $article, 'comments' => $comments, 'page' => $page, 'pending' => $pending));
}
示例2: showAction
public function showAction()
{
//Pass all the posts to the views
$this->view->setVar("posts", Posts::find());
//Using the magic setter
$this->view->posts = Posts::find();
//Passing more than one variable at the same time
$this->view->setVars(array('title' => $post->title, 'content' => $post->content));
}
示例3: searchAction
/**
* Поиск должностей по параметрам
*/
public function searchAction()
{
$query = Criteria::fromInput($this->di, "Posts", array_merge($_GET, $_POST));
$this->persistent->parameters = $query->getParams();
$parameters = $this->persistent->parameters;
if (!is_array($parameters)) {
$parameters = array();
}
$posts = \Posts::find($parameters)->toArray(true);
$this->view->disable();
$this->response->setContentType('application/json', 'UTF-8');
echo json_encode($posts);
}
示例4: indexAction
public function indexAction()
{
$this->view->disable();
//no view here
$post_array = array();
$posts = Posts::find();
$posts->rewind();
while ($posts->valid()) {
$post = $posts->current();
array_unshift($post_array, array('title' => $post->getTitle(), 'content' => $post->getContent(), 'id' => $post->id()));
$posts->next();
}
return (new \Phalcon\Http\Response())->setContent(json_encode($post_array));
}
示例5: getAction
public function getAction()
{
$this->view->disable();
if ($this->request->isGet() == true) {
$posts = Posts::find();
foreach ($posts as $post) {
$this->_posts[] = $post;
}
$this->response->setJsonContent(array("posts" => $this->_posts));
$this->response->setStatusCode(200, "OK");
$this->response->send();
} else {
$this->response->setStatusCode(404, "Not Found");
}
}
示例6: showPost
public function showPost($postID)
{
$memberID = Session::get('key');
$post = Posts::find($postID);
$member = Members::find($post->memberID);
$data = array('post' => $post, 'memberID' => $memberID, 'member' => $member);
if (Session::get('adminLoggedIn')) {
//adminse
return View::make('admin/showPostForAdmin', $data);
}
if ($memberID == "") {
//member değilse
return View::make('showPost', $data);
}
return View::make('member/showPostForMember', $data);
//membersa
}
示例7: postsAction
public function postsAction()
{
$request = new Request();
$this->view->setVar("title", "Посади");
$search = trim($request->get("search"));
$pageCount = $request->get("page-count") ? $request->get("page-count") : $this->session->get("page-count");
if ($pageCount) {
$this->session->set("page-count", $pageCount);
}
$orderColumn = trim($request->get("order-column")) . " " . trim($request->get("order-type"));
$paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => \Posts::find(array("order" => trim($orderColumn) ? $orderColumn : "title ASC", "conditions" => "title LIKE ?1", "bind" => array(1 => "%" . $search . "%"))), "limit" => $pageCount ? $pageCount : 30, "page" => $request->get("page")));
$page = $paginator->getPaginate();
$this->view->page = $page;
$this->view->countItems = count($page->items);
$this->view->search = $search;
$this->view->orderColumn = $request->get("order-column");
$this->view->orderType = $request->get("order-type");
$this->view->pageCount = $pageCount;
}
示例8: article
public function article($slug = '')
{
// find article
$params = array('slug' => $slug);
// allow admin to view unpublished posts
if (Users::authed() === false) {
$params['status'] = 'published';
}
if (($article = Posts::find($params)) === false) {
return Response::error(404);
}
// add comment
if (Input::method() == 'POST') {
if (Comments::add($article->id)) {
$page = IoC::resolve('posts_page');
return Response::redirect($page->slug . '/' . $article->slug);
}
}
// register single item for templating functions
IoC::instance('article', $article, true);
Template::render('article');
}
示例9: getPostsAction
public function getPostsAction($gid = NULL)
{
if ($gid == NULL) {
if ($this->request->get("stafflistGroup")) {
$gid = $this->request->get("stafflistGroup");
} else {
$result = NULL;
}
} else {
$posts = \Posts::find();
$stafflists = \Stafflist::find("stafflist_group=" . $gid);
$result = array();
foreach ($posts as $post) {
if (!$this->checkPostInStaff($post, $stafflists)) {
$result[] = $post->toArray(true);
}
}
}
$this->view->disable();
$this->response->setContentType('application/json', 'UTF-8');
echo json_encode($result);
}
示例10: searchAction
/**
* Searches for posts
*/
public function searchAction()
{
$numberPage = 1;
if ($this->request->isPost()) {
$query = Criteria::fromInput($this->di, "Posts", $_POST);
$this->persistent->parameters = $query->getParams();
} else {
$numberPage = $this->request->getQuery("page", "int");
}
$parameters = $this->persistent->parameters;
if (!is_array($parameters)) {
$parameters = array();
}
$parameters["order"] = "id";
$posts = Posts::find($parameters);
if (count($posts) == 0) {
$this->flash->notice("The search did not find any posts");
return $this->dispatcher->forward(array("controller" => "posts", "action" => "index"));
}
$paginator = new Paginator(array("data" => $posts, "limit" => 10, "page" => $numberPage));
$this->view->page = $paginator->getPaginate();
}
示例11: index
public function index()
{
$posts = Posts::find();
return Rs::p(1, 'All Posts', $posts);
}
示例12: showAction
public function showAction()
{
//Pass all the posts to the views
$this->view->setVar("posts", Posts::find());
}
示例13: die
$data['created_at'] = $posts[$i]['created_at'];
$author = Users::find($posts[$i]['author_id']);
$data['author'] = $author->firstname;
}
$results[] = $data;
die(json_encode($results));
});
$app->post('/api/v1/posts', function () use($app) {
$posts = new Posts();
$posts->title = $app->request()->post('title');
$posts->slug = str_replace(' ', '-', $app->request()->post('slug'));
$posts->content = $app->request()->post('content');
$posts->author_id = $app->request()->post('post_type');
$posts->author_id = $app->request()->post('author_id');
$posts->save();
die(json_encode($posts));
});
$app->put('/api/v1/posts/:id', function ($id) use($app) {
$posts = Posts::find($id);
$posts->title = $app->request()->post('title');
$posts->slug = str_replace(' ', '-', $app->request()->post('slug'));
$posts->content = $app->request()->post('content');
$posts->author_id = $app->request()->post('author_id');
$posts->save();
die(json_encode($posts));
});
$app->delete('/api/v1/posts/:id', function ($id) use($app) {
$posts = Posts::find($id);
$posts->delete();
die(json_encode($posts));
});
示例14: function
});
//GET THE PARTICULAR USER
$app->get('/api/v1/pages/:slug', function ($slug) use($app) {
$response = $app->response();
$response->header('Access-Control-Allow-Origin', '*');
$pages = Posts::where('slug', $slug)->first();
$response->write(json_encode($pages));
});
$app->post('/api/v1/pages', function () use($app) {
$pages = new Posts();
$pages->title = $app->request()->post('title');
$pages->slug = str_replace(' ', '-', $app->request()->post('slug'));
$pages->content = $app->request()->post('content');
$pages->author_id = $app->request()->post('author_id');
$pages->save();
die(json_encode($pages));
});
$app->put('/api/v1/pages/:id', function ($id) use($app) {
$pages = Posts::find($id);
$pages->title = $app->request()->post('title');
$pages->slug = str_replace(' ', '-', $app->request()->post('slug'));
$pages->content = $app->request()->post('content');
$pages->author_id = $app->request()->post('author_id');
$pages->save();
die(json_encode($pages));
});
$app->delete('/api/v1/pages/:id', function ($id) use($app) {
$pages = Posts::find($id);
$pages->delete();
die(json_encode($pages));
});
示例15: function
<?php
$app->get('/(:page)', function ($page = 1) use($app, $settings) {
$p = Posts::count();
$pages = ceil($p / $settings->post_per_page);
if ($page > $pages) {
$app->pass();
}
$posts = Posts::orderBy('creation', 'desc')->skip($settings->post_per_page * ($page - 1))->take($settings->post_per_page)->get();
$arr = array();
//Posts
foreach ($posts as $post) {
if ($post['active'] == 'true') {
$post['author'] = Users::get_author($post['user_id']);
$post['date'] = date('d-m-Y H:i', $post['creation']);
$post['url'] = $app->request->getUrl() . $app->request->getPath() . 'post/' . $post['id'];
if ($settings->truncate == 'true') {
$text = truncate_to_n_words($post['text'], 70, $post['url']);
$post['text'] = $app->markdown->parse($text);
} else {
$post['text'] = $app->markdown->parse($post['text']);
}
$post['count'] = Posts::find($post['id'])->comments->count();
$arr[] = $post;
}
}
$app->render('posts.html', array('posts' => $arr, 'pages' => $pages, 'page' => $page));
})->conditions(array('page' => '\\d+'));