本文整理汇总了PHP中AppBundle\Entity\Post::setCreated方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::setCreated方法的具体用法?PHP Post::setCreated怎么用?PHP Post::setCreated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppBundle\Entity\Post
的用法示例。
在下文中一共展示了Post::setCreated方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: load
public function load(ObjectManager $manager)
{
// TODO: Implement load() method.
$category = new Category();
$category->setName('Default');
$manager->persist($category);
foreach (range(1, 100) as $i) {
$post = new Post();
$post->setTitle($this->getPostTitle());
$post->setSlug($this->container->get('slugger')->slugify($post->getTitle()));
$post->setImage('post.jpeg');
$post->setContent($this->getPostContent());
$post->setAuthor('gunyem');
$post->setCreated(new \DateTime('now - ' . $i . 'days'));
$post->setUpdated(new \DateTime('now - ' . $i . 'days'));
$post->setCategory($category);
foreach (range(1, 10) as $j) {
$comment = new Comment();
$comment->setPost($post);
$comment->setContent($this->getPostTitle());
$comment->setAuthor('gunyem');
$comment->setCreated(new \DateTime('now + ' . ($i + $j) . 'seconds'));
$manager->persist($comment);
$post->createComment($comment);
}
$manager->persist($post);
}
$manager->flush();
}
示例3: load
public function load(ObjectManager $manager)
{
foreach ($this->getData() as $payload) {
$post = new Entity\Post();
$post->setTitle($payload[0]);
$post->setContent($payload[1]);
$post->setCreated($payload[2]);
$manager->persist($post);
}
$manager->flush();
}