本文整理汇总了PHP中Post类的典型用法代码示例。如果您正苦于以下问题:PHP Post类的具体用法?PHP Post怎么用?PHP Post使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Post类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addPost
public function addPost($user_id, $title, $content)
{
$post = new Post();
$post->savePost($user_id, $title, $content);
$view = new PostView();
$view->renderSavedPost();
}
示例2: makePost
protected function makePost()
{
$post = new Post();
$post->title = "titulo";
$post->save();
return $post;
}
示例3: run
public function run()
{
$user = User::firstOrFail();
$post1 = new Post();
$post1->title = 'A Long Long';
$post1->subtitle = 'In a Galaxy Far Far Away';
$post1->content = 'Lorem ipsum dolor sit amet, ut numquam repudiandae vim, vix no novum saperet appellantur. Periculis signiferumque ea pri, et dolore conceptam sit. Nominavi facilisi cu vix, eos ut probatus suavitate, solum utinam epicuri ex vis. Quis appareat quaestio et sit, ei pri illud eripuit lobortis, vis modus vivendo tacimates at. Quem moderatius pri in, ut brute noster dicunt his, graeci definitiones mei an';
$post1->image = '/img/264H.jpg';
$post1->user_id = $user->id;
$post1->save();
$post2 = new Post();
$post2->title = 'A Long Long Time';
$post2->subtitle = 'In a Galaxy Far Far Away';
$post2->content = 'Lorem ipsum dolor sit amet, ut numquam repudiandae vim, vix no novum saperet appellantur. Periculis signiferumque ea pri, et dolore conceptam sit. Nominavi facilisi cu vix, eos ut probatus suavitate, solum utinam epicuri ex vis. Quis appareat quaestio et sit, ei pri illud eripuit lobortis, vis modus vivendo tacimates at. Quem moderatius pri in, ut brute noster dicunt his, graeci definitiones mei an';
$post2->image = '/img/264H.jpg';
$post2->user_id = $user->id;
$post2->save();
$post3 = new Post();
$post3->title = 'A Long Long Time Ago';
$post3->subtitle = 'In a Galaxy Far Far Away';
$post3->content = 'Lorem ipsum dolor sit amet, ut numquam repudiandae vim, vix no novum saperet appellantur. Periculis signiferumque ea pri, et dolore conceptam sit. Nominavi facilisi cu vix, eos ut probatus suavitate, solum utinam epicuri ex vis. Quis appareat quaestio et sit, ei pri illud eripuit lobortis, vis modus vivendo tacimates at. Quem moderatius pri in, ut brute noster dicunt his, graeci definitiones mei an';
$post3->image = '/img/264H.jpg';
$post3->user_id = $user->id;
$post3->save();
}
示例4: run
public function run()
{
$user = User::firstOrFail();
$post1 = new Post();
$post1->title = '1st Blog Post';
$post1->username = 'admin';
$post1->date = '2016-01-11';
$post1->description = 'This is my first blog post on my laravel blog';
$post1->user_id = $user->id;
$post1->save();
$post2 = new Post();
$post2->title = '2nd Blog Post';
$post2->username = 'admin';
$post2->date = '2016-01-11';
$post2->description = 'This is my second blog post.';
$post2->user_id = $user->id;
$post2->save();
$post3 = new Post();
$post3->title = '3rd Blog Post';
$post3->username = 'admin';
$post3->date = '2016-01-11';
$post3->description = 'This is my third blog post';
$post3->user_id = $user->id;
$post3->save();
}
示例5: controlerJob
public function controlerJob($maincont)
{
if ($maincont->isLoggued()) {
if (isset($_POST["title"])) {
$p = new Post();
$p->setTitle($_POST["title"]);
$p->setBody($_POST["body"]);
$p->setHour(date("h:i:s"));
$p->setDate(date("Y-m-d"));
// gestion des tags
$tags = explode(" ", $_POST["tags"]);
foreach ($tags as $t) {
if ($t == "") {
continue;
}
$ta = Tag::getByTag($t);
//echo "Tag : $t<br />";
if (count($ta) == 0) {
$mytag = new Tag();
$mytag->setTag($t);
} else {
$mytag = $ta[0];
}
// création du posttag liant le tag et le post
$pt = new Posttag();
$pt->setPostid($p->id);
$pt->setTagid($mytag->id);
}
}
$maincont->goModule("post", "admin");
} else {
$maincont->goModule("home", "display");
}
}
示例6: run
public function run()
{
$user = User::firstOrFail();
$post1 = new Post();
$post1->title = 'Calculator';
$post1->body = 'Early in Codeup, I made a calculator that functions using JavaScript\'s internal math functions to do the computations. I styled the calculator to look somewhat real, and I was very happy with the glossy buttons I was able to make with some CSS befores and afters. I was also able to approximate the old school real LED display with some CSS gradients. Lastly, there\'s a not-at-all subtle Star Wars reference on the calculator in the lower left corner. Anyone catch the reference?';
$post1->image_url = 'img/cal.png';
$post1->user_id = $user->id;
$post1->save();
$post2 = new Post();
$post2->title = 'Weather API';
$post2->body = 'I got to say that the weather API was a lot of fun. It was incredible to see the two APIs (Open Weather and Google Maps) come together and see how AJAX requests work with JavaScript and jQuery. I kept the CSS simple here, but I like the layout in those square units I created. I feel like it gets the important info out there in a format that is easy to read and look at. I am especially proud of the search area which has the added reverse address look up. Normally, one types in an address and gets the weather for that location. But if one drags the map pin, the search area will also display an address for that location as well. Very neat!';
$post2->image_url = 'img/weather.png';
$post2->user_id = $user->id;
$post2->save();
$post3 = new Post();
$post3->title = 'Simon Says';
$post3->body = 'Simon Says was my first game using JavaScript and jQuery. I did my best to make my Simon to look like the childhood favorite of yesteryear. I\'m so happy with the name plate area. That CSS was a blast to figure out with the metalic shine and realistic buttons! Of course, the real star of this game is the jQuery animations that make it all work.';
$post3->image_url = 'img/simon.png';
$post3->user_id = $user->id;
$post3->save();
$post4 = new Post();
$post4->title = 'Whack-a-mole';
$post4->body = 'Or Whack-a-gopher as I\'ve made it! This game was an amazing build and it was so much fun! I admit it, I got carried away with making each and every game element out of HTML and CSS. I used no images whatsoever! And I think it was totally worth it. This is also where I started to really become fond of CSS animations as I figured out how to make each gopher spin like a 3D game piece upon being clicked. ';
$post4->image_url = 'img/mole.png';
$post4->user_id = $user->id;
$post4->save();
$post5 = new Post();
$post5->title = 'Spatula City';
$post5->body = 'Or our ad lister/Craigslist clone. I made this call-back to the 80s and Weird Al with Zeshan Segal and Reagan Wilkins. Together I think we made a fantastic site for selling and buying spatulas of all sorts, shapes and colors! I was responsible for the ad create form, the ad edit form, and the ads DB table. It was challenging to make the ad edit form which retrieved data from the DB for it to be altered. I also built the ads index page and the ads show pages. Within those two pages, I am super pleased with the categories bar that allows one to filter the ads showing on the ads index page in real time. I used PHP\'s ability to query MySQL and added a change listener with jQuery to submit the radio button selected. That was a great breakthrough for me. To showcase this project, which was never a live site, I have decided to show a few screenshots. Each screenshot shows one of the items I worked to develop such as the navbar, the ads index page (aka the Product page), and the deals page (the dancing spatulas).';
$post5->image_url = 'img/adlister.png';
$post5->user_id = $user->id;
$post5->save();
}
示例7: testCounterIncrementsAndDecrementsWhen
public function testCounterIncrementsAndDecrementsWhen()
{
$post_with_comments = new Post();
$post_with_comments->title = 'post 1';
$this->assertTrue($post_with_comments->save());
$post_without_comments = new Post();
$post_without_comments->title = 'post 2';
$this->assertTrue($post_without_comments->save());
//Create 10 comments, ensure counter increments
for ($i = 1; $i <= 10; $i++) {
$comment = new Comment();
$comment->postId = $post_with_comments->id;
$comment->text = 'comment ' . $i;
$this->assertTrue($comment->save());
$post_with_comments->refresh();
$post_without_comments->refresh();
$this->assertEquals($post_with_comments->commentsCount, $i);
$this->assertEquals($post_without_comments->commentsCount, 0);
}
//Delete all comments, ensure counter decrements
$comments = Comment::find()->all();
$count = count($comments);
foreach ($comments as $comment) {
$this->assertEquals($comment->delete(), 1);
$count--;
$post_with_comments->refresh();
$this->assertEquals($post_with_comments->commentsCount, $count);
}
}
示例8: actionCreate
/**
* 录入
*
*/
public function actionCreate()
{
parent::_acl();
$model = new Post();
$attr = $this->_gets->getPost('attr');
$imageList = $this->_gets->getPost('imageList');
$imageListSerialize = XUtils::imageListSerialize($imageList);
if (isset($_POST['Post'])) {
$style = $this->_gets->getPost('style');
$acl = $this->_gets->getPost('acl');
$styleFormat = XUtils::titleStyle($style);
$file = XUpload::upload($_FILES['attach'], array('thumb' => true, 'thumbSize' => array(400, 250)));
$model->attributes = $_POST['Post'];
if (is_array($file)) {
$model->attach_status = 'Y';
$model->attach_file = $file['pathname'];
$model->attach_thumb = $file['paththumbname'];
}
$model->title_style = $styleFormat['text'];
$model->title_style_serialize = $styleFormat['serialize'];
$model->acl = is_array($acl) ? implode(',', $acl) : '';
$model->image_list = $imageListSerialize['dataSerialize'];
if ($model->save()) {
Attr::create($model->id, $attr);
Post2tags::build('create', $_POST['Post']['tags'], $model->id, $model->catalog_id);
AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入内容,ID:' . $model->id));
$this->redirect(array('index'));
}
}
$attrData = Attr::dataReset($attr);
$attrModel = Attr::lists($model->catalog_id, 'post');
$this->render('create', array('model' => $model, 'imageList' => $imageListSerialize['data'], 'attrModel' => $attrModel, 'attrData' => $attrData));
}
示例9: archiveMonths
public function archiveMonths()
{
$postManager = new Post();
$sql = "SELECT DISTINCT DATE_FORMAT(posted_at, '%Y') AS year, DATE_FORMAT(posted_at, '%m') AS month FROM posts WHERE is_active = 1 ORDER BY year DESC, month DESC";
$res = $postManager->getAdapter()->query($sql)->fetchAll();
return $res;
}
示例10: toHistoryString
/**
* return the string to appear in the history
*
* @param Post $post
* @return string
*/
public static function toHistoryString($post)
{
$controller = sfContext::getInstance()->getController();
$link = $controller->genUrl('@view_thread?thread_id=' . $post->getThreadId());
$link = sprintf('<a href="%s">%s</a>', $link, 'forum thread');
return sprintf('posted on a %s', $link);
}
示例11: editPost
public function editPost(Post $post)
{
$STH = $this->DBH->prepare("UPDATE Posts SET textpost=:textpost, title=:title\n WHERE id=:id");
$STH->bindValue(":textpost", $post->getTextpost());
$STH->bindValue(":title", $post->getTitle());
$STH->execute();
}
示例12: send
public function send()
{
$author = !empty($_POST['author']) ? strip_tags($_POST['author']) : '';
$content = !empty($_POST['content']) ? htmlspecialchars($_POST['content']) : '';
$errors = array();
if (!empty($_POST)) {
$post = new Post();
foreach ($_POST as $key => $value) {
try {
$post->{$key} = $value;
} catch (Exception $e) {
$errors[$key] = $e->getMessage();
}
}
if (empty($errors)) {
$result_id = $post->insert();
if ($result_id > 0) {
header('Location: post.php?id=' . $result_id);
exit;
}
$errors['internal error'] = 'An error occured, please try again later';
}
}
$vars = array('author' => $author, 'content' => $content, 'errors' => $errors);
Post::displayTemplate('send.tpl', $vars);
}
示例13: new_comment
/**
* inserts a new comment
*
* @param $data array
*
* @return int(id)|string(error)
*/
public static function new_comment($data)
{
$database = new Database();
$post = new Post();
$PostID = $data['post_id'];
$content = $data['content'];
$token = $data['token'];
if (empty(trim($content))) {
die("Comment can't be empty");
}
$qna = new QNA();
if (!is_object($qna->get_question($PostID)) && !is_array($post->get_post($PostID, true))) {
die("Error! Post was not found.");
}
if (!Token::validateToken($token)) {
die("Error! Please try again later");
}
unset($data['token']);
$data['uid'] = USER_ID;
$insert = $database->insert_data(TABLE_COMMENTS, $data);
if ($insert === true && $database->error === false) {
// success
return (int) $database->lastId;
} else {
return array_shift($database->errors);
}
}
示例14: viewAction
public function viewAction()
{
$label = $this->_getParam('label');
if ($label === null) {
throw new Zend_Exception('No label specified in TagsController::viewAction()');
}
$tagManager = new Tag();
$tag = $tagManager->fetchRow(array('label = ?' => $label));
if ($tag === null) {
throw new Zend_Exception('Tag not found in TagsController::viewAction()');
}
$this->view->tag = $tag;
// get posts
$page = array_key_exists('p', $_GET) ? $_GET['p'] : 1;
$page = $page < 1 ? 1 : $page;
$this->view->page = $page;
$postManager = new Post();
$postCount = $postManager->fetchAll(array('id IN (SELECT post_id FROM posts_tags WHERE tag_id = ?)' => $tag->id, 'is_active = ?' => 1))->count();
$this->view->pageCount = ceil($postCount / 10);
$this->view->posts = $postManager->fetchAll(array('id IN (SELECT post_id FROM posts_tags WHERE tag_id = ?)' => $tag->id, 'is_active = ?' => 1), 'posted_at DESC', 10, ($page - 1) * 10);
$this->view->paginationBase = '/tags/' . $tag->label;
// description
$this->view->metaDescription = 'Read my posts tagged with \'' . $tag->title . '\'.';
// set title
$this->_title('Posts tagged with \'' . $tag->title . '\'');
$this->_forward('listing', 'posts');
}
示例15: prepareSidebar
/**
* Prepare sidebar data, random tags and archive list
*/
private function prepareSidebar()
{
//if tags cache exist, skip retrieving from DB, expires every 5 minutes
$cacheTagOK = Doo::cache('front')->testPart('sidebarTag', 300);
if (!$cacheTagOK) {
echo '<h2>Cache expired. Get Tags from DB!</h2>';
//get random 10 tags
Doo::loadModel('Tag');
$tags = new Tag();
$this->data['randomTags'] = $tags->limit(10, null, null, array('custom' => 'ORDER BY RAND()'));
} else {
$this->data['randomTags'] = array();
}
//if archive cache exist, skip retrieving from DB, archive expires when Post added, updated, deleted
$cacheArchiveOK = Doo::cache('front')->testPart('sidebarArchive', 31536000);
if (!$cacheArchiveOK) {
echo '<h2>Cache expired. Get Archives from DB!</h2>';
//you can pass data to constructor to set the Model properties
Doo::loadModel('Post');
$p = new Post(array('status' => 1));
$this->data['archives'] = $p->getArchiveSummary();
} else {
$this->data['archives'] = array();
}
}