本文整理汇总了PHP中AppBundle\Entity\Post类的典型用法代码示例。如果您正苦于以下问题:PHP Post类的具体用法?PHP Post怎么用?PHP Post使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Post类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createAction
/**
* @Route("/create", name="create_objects")
*
* @Rest\View()
*
* @return Response
*/
public function createAction()
{
// We need an entity manager here
$em = $this->getDoctrine()->getManager();
// First, we try to create a post
$post = new Post();
$post->setTitle('Hello World');
$post->setContent('This is a hello world post');
$post->setCreated(new \DateTime());
$em->persist($post);
// Create new post log object
$postLog = new PostLog();
$postLog->setMessage('A new post was created');
$postLog->setCreated(new \DateTime());
$postLog->setParent($post);
$em->persist($postLog);
// Try to create a category
$category = new Category();
$category->setTitle('A Category');
$category->setDescription('A category to created');
$em->persist($category);
// Create new category log object
$categoryLog = new CategoryLog();
$categoryLog->setMessage('A new category was created');
$categoryLog->setCreated(new \DateTime());
$categoryLog->setParent($category);
$em->persist($categoryLog);
// Actually store all the entities to the database
// to get id of the post and the category
$em->flush();
return ['Done'];
}
示例2: addAction
/**
* @Route("/post/add/{id}", name="addPost")
*/
public function addAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$topic = $em->getRepository('AppBundle:Topic')->find($id);
if (!$topic) {
throw $this->createNotFoundException('No Topic found for id ' . $id);
}
$post = new Post();
$post->setDate(new \DateTime('now'));
$loggedIn = false;
$securityContext = $this->container->get('security.authorization_checker');
if ($securityContext->isGranted('IS_AUTHENTICATED_FULLY')) {
$token = $this->get('security.token_storage')->getToken();
/* @var $user User */
$user = $token->getUser();
$post->setAuthor($user);
$post->setTopic($topic);
$loggedIn = true;
}
$form = $this->createFormBuilder($post)->add('content', TextareaType::class)->add('save', SubmitType::class, array('label' => 'Reply'))->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em->persist($post);
$em->flush();
return $this->render('Topic/watch.html.twig', array('topic' => $topic, 'form' => $form->createView(), 'loggedIn' => $loggedIn));
}
return $this->render('Post/add.html.twig', array('topic' => $topic, 'form' => $form->createView(), 'loggedIn' => $loggedIn));
}
示例3: loadPosts
private function loadPosts(ObjectManager $manager)
{
$passwordEncoder = $this->container->get('security.password_encoder');
$user = new User();
$user->setUsername('vvasia');
$user->setDisplayName('Vasia Vasin');
$user->setEmail('v.vasin_fake@levi9.com');
$user->setUuid('uuid');
$encodedPassword = $passwordEncoder->encodePassword($user, 'password');
$user->setPassword($encodedPassword);
$user->setRoles(['ROLE_USER']);
$manager->persist($user);
$manager->flush();
/** @var User $author */
$author = $manager->getRepository('AppBundle:User')->findOneBy(['email' => 'fakeuser2@levi9.com']);
foreach (range(1, 10) as $i) {
$post = new Post();
$post->setTitle($this->getRandomPostTitle() . ' ' . uniqid())->setSummary($this->getRandomPostSummary())->setSlug($this->container->get('slugger')->slugify($post->getTitle()))->setContent($this->getPostContent())->setAuthor($author)->setPublishedAt(new \DateTime('now - ' . $i . 'days'))->setState($this->getRandomState())->setCategory($category);
foreach (range(1, 5) as $j) {
$comment = new Comment();
$comment->setUser($user)->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds'))->setContent($this->getRandomCommentContent())->setPost($post);
$manager->persist($comment);
$post->addComment($comment);
}
if (rand(0, 1)) {
$vote = new Vote();
$vote->setAuthorEmail(rand(0, 1) ? 'fakeuser2@levi9.com' : 'fakeuser1@levi9.com');
$vote->setPost($post);
$vote->setVote(rand(0, 1));
}
$manager->persist($post);
$category->addPost($post);
}
$manager->flush();
}
示例4: createAction
/**
* @Route("/create", name="create_post")
*/
public function createAction(Request $request)
{
// just setup a fresh $post object (remove the dummy data)
$post = new Post();
$post->setAuthorEmail('dipsetm12@hotmail.fr');
$form = $this->createForm(new PostType(), $post);
$finder = new Finder();
$data = $finder->files()->in($_SERVER['DOCUMENT_ROOT'] . 'Benedictux/web/upload');
//$data = $this->get('app.scanner')->scanDir($_SERVER['DOCUMENT_ROOT'].'Benedictux/web/uploads');
//$data = $this->get('app.scanner')->scanDirectory($this->get('request')->getBasePath());
//$scanned_directory = array_diff(scandir('./web'), array('..', '.'));
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$slug = $this->get('app.slugger')->slugify($post->getTitle());
$post->setSlug($slug);
if (get_magic_quotes_gpc()) {
$content = stripslashes($post->getContent());
$content = $this->get('app.parser')->parserTexarea($content);
$post->setContent($content);
} else {
$content = $this->get('app.parser')->parserTexarea($post->getContent());
$post->setContent($content);
}
$em->persist($post);
$em->flush();
return $this->redirectToRoute('accueil');
}
return $this->render('app/postCreate.html.twig', array('form' => $form->createView(), 'data' => $data));
}
示例5: newAction
/**
* Displays a form to create a new Post entity.
*
* @Route("/new", name="admin_post_new")
* @Method("GET")
* @Template()
*/
public function newAction()
{
$entity = new Post();
$entity->setCreatedAt();
$form = $this->createCreateForm($entity);
return array('entity' => $entity, 'form' => $form->createView());
}
示例6: addPostAction
/**
* @Route("{page}/temat/{temat}")
*/
public function addPostAction(Request $request, $temat, $page)
{
if ($this->getUser() == true) {
$task = new Post();
$task->setAutor($this->getUser()->getUsername());
$task->setIdTematu($temat);
$task->setCzasAdd(new \DateTime("now"));
$form = $this->createFormBuilder($task)->add('Tresc', TextareaType::class)->add('Zapisz', SubmitType::class, array('label' => 'Dodaj'))->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->savePost($task);
$this->upgradePost($page);
}
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery("SELECT u FROM AppBundle:Post u WHERE u.idTematu = :id ");
$query->setParameter('id', $temat);
$tematy = $query->getResult();
$size = sizeof($tematy);
return $this->render('Posts/post_page.html.twig', array('form' => $form->createView(), 'size' => $size, 'tematy' => $tematy, "page" => $page));
} else {
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery("SELECT u FROM AppBundle:Post u WHERE u.idTematu = :id ");
$query->setParameter('id', $temat);
$tematy = $query->getResult();
$size = sizeof($tematy);
return $this->render('Posts/post_page.html.twig', array('size' => $size, 'tematy' => $tematy, "page" => $page));
}
}
示例7: blogAction
/**
* @Route("/channel/{uniqID}/blog", name="oktothek_series_blog_post")
* @Method({"GET", "POST"})
* @Template()
*/
public function blogAction(Request $request, Series $series)
{
$this->denyAccessUnlessGranted('edit_channel', $series);
$post = new Post();
$post->setIsActive(true);
$form = $this->createForm(PostType::class, $post, ['action' => $this->generateUrl('oktothek_series_blog_post', ['uniqID' => $series->getUniqID()])]);
$form->add('submit', SubmitType::class, ['label' => 'oktothek.post_create_button', 'attr' => ['class' => 'btn btn-primary']]);
if ($request->getMethod() == "POST") {
//sends form
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$series->addPost($post);
foreach ($post->getAssets() as $asset) {
$asset->setSeries($series);
$em->persist($asset);
}
$em->persist($post);
$em->persist($series);
$em->flush();
$this->get('session')->getFlashBag()->add('success', 'oktothek.success_create_post');
$this->get('oktothek_notification_service')->createNewPostNotifications($post);
return $this->redirect($this->generateUrl('oktothek_channel_blogposts', ['uniqID' => $series->getUniqID()]));
} else {
$this->get('session')->getFlashBag()->add('error', 'oktothek.error_create_post');
}
}
return ['form' => $form->createView(), 'series' => $series];
}
示例8: canEdit
private function canEdit(Post $post, UserInterface $user, TokenInterface $token)
{
if ($this->decisionManager->decide($token, ['ROLE_MANAGER']) && $post->getOwner() == $user) {
return true;
}
return false;
}
示例9: addPost
public function addPost(Post $post, User $user)
{
$post->setAuthor($user);
$this->em->persist($post);
$user->setLastPost($post);
$user->increasePostsCount();
$this->em->flush();
}
示例10: save
public function save(Post $entity)
{
$entity->setUpdated(date_create());
$entityManager = $this->getEntityManager();
$entityManager->persist($entity);
$entityManager->flush();
return $entity;
}
示例11: delete
/**
* @return int
*/
public function delete(User $user, Post $post)
{
$conn = $this->_em->getConnection();
$statement = $conn->prepare('DELETE FROM post_vote WHERE user_id = :user_id AND post_id = :post_id');
$statement->bindValue('user_id', $user->getId());
$statement->bindValue('post_id', $post->getId());
return $statement->execute();
}
示例12: createBlogAction
/**
* @Route("/create-blog", name="create-blog")
*/
public function createBlogAction(Request $request)
{
$post = new Post();
$post->setDescription('Nuevo post');
$em = $this->getDoctrine()->getManager();
$em->persist($post);
$em->flush();
return new Response('Created post id ' . $post->getId());
}
示例13: canEdit
private function canEdit(Post $post, User $user)
{
// this assumes that the data object has a getOwner() method
// to get the entity of the user who owns this data object
//if ($post->getAuthor()->getIsAdmin() and !$user->getIsAdmin()) {
// return false;
//}
return $user === $post->getAuthor() or $user->getIsAdmin();
}
示例14: createAction
/**
* Creates a new Post entity.
*
* @Route("/", name="post_create")
* @Method("POST")
*/
public function createAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$post = new Post();
$post->setContent($request->getContent());
$em->persist($post);
$em->flush();
return new JsonResponse();
}
示例15: load
public function load(ObjectManager $manager)
{
$repo = new Post();
$repo->setTitle('Post title 1');
$manager->persist($repo);
$repo = new Post();
$repo->setTitle('Post title 2');
$manager->persist($repo);
$manager->flush();
}