本文整理汇总了PHP中AppBundle\Entity\Post::setCategory方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::setCategory方法的具体用法?PHP Post::setCategory怎么用?PHP Post::setCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppBundle\Entity\Post
的用法示例。
在下文中一共展示了Post::setCategory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: loadPosts
private function loadPosts(ObjectManager $manager)
{
$category = new Category();
$category->setName('Improvements');
foreach (range(1, 5) as $i) {
$post = new Post();
$post->setTitle($this->getRandomPostTitle());
$post->setSummary($this->getRandomPostSummary());
$post->setSlug($this->container->get('slugger')->slugify($post->getTitle()));
$post->setContent($this->getPostContent());
$post->setAuthorEmail('a.martynenko@levi9.com');
$post->setPublishedAt(new \DateTime('now - ' . $i . 'days'));
$post->setState($this->getRandomState());
$post->setCategory($category);
foreach (range(1, 5) as $j) {
$comment = new Comment();
$comment->setAuthorEmail('d.kiprushev@levi9.com');
$comment->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds'));
$comment->setContent($this->getRandomCommentContent());
$comment->setPost($post);
$manager->persist($comment);
$post->addComment($comment);
}
if (rand(0, 1)) {
$vote = new Vote();
$vote->setAuthorEmail(rand(0, 1) ? 'a.martynenko@levi9.com' : 'd.kiprushev@levi9.com');
$vote->setPost($post);
$vote->setVote(rand(0, 1));
}
$manager->persist($post);
$category->addPost($post);
}
$manager->flush();
}
示例3: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$post = new Post();
$post->setTitle('Cras dignissim vestibulum ultrices');
$post->setSummary($this->getPostSummary());
$post->setContent($this->getPostContent());
$post->setAuthor($this->getReference('user-john_admin'));
$post->setCategory($this->getReference('category-Vestibulum'));
$post->addTag($this->getReference('tag-volutpat'));
$post->addTag($this->getReference('tag-enim'));
$post->addTag($this->getReference('tag-bibendum'));
$manager->persist($post);
$this->setReference('post-1', $post);
$post = new Post();
$post->setTitle('Neque porro quisquam est qui dolorem');
$post->setSummary($this->getPostSummary());
$post->setContent($this->getPostContent());
$post->setAuthor($this->getReference('user-john_admin'));
$post->setCategory($this->getReference('category-Dolorem'));
$post->addTag($this->getReference('tag-uspendisse'));
$post->addTag($this->getReference('tag-imperdiet'));
$post->addTag($this->getReference('tag-ullamcorper'));
$manager->persist($post);
$this->setReference('post-2', $post);
$post = new Post();
$post->setTitle('Ut enim ad minim veniam, quis nostrud');
$post->setSummary($this->getPostSummary());
$post->setContent($this->getPostContent());
$post->setAuthor($this->getReference('user-john_admin'));
$post->setCategory($this->getReference('category-Nostrud'));
$post->addTag($this->getReference('tag-lacus'));
$post->addTag($this->getReference('tag-aliquam'));
$post->addTag($this->getReference('tag-eumassa'));
$manager->persist($post);
$this->setReference('post-3', $post);
$post = new Post();
$post->setTitle('Duis aute irure dolor in reprehenderit');
$post->setSummary($this->getPostSummary());
$post->setContent($this->getPostContent());
$post->setAuthor($this->getReference('user-john_admin'));
$post->setCategory($this->getReference('category-Reprehenderit'));
$post->addTag($this->getReference('tag-utnunc'));
$post->addTag($this->getReference('tag-gravida'));
$post->addTag($this->getReference('tag-ullamcorper'));
$manager->persist($post);
$this->setReference('post-4', $post);
$post = new Post();
$post->setTitle('Excepteur sint occaecat cupidatat proident');
$post->setSummary($this->getPostSummary());
$post->setContent($this->getPostContent());
$post->setAuthor($this->getReference('user-john_admin'));
$post->setCategory($this->getReference('category-Dolorem'));
$post->addTag($this->getReference('tag-uspendisse'));
$post->addTag($this->getReference('tag-maecenas'));
$post->addTag($this->getReference('tag-justo'));
$manager->persist($post);
$this->setReference('post-5', $post);
$post = new Post();
$post->setTitle('Aenean eget lobortis lectus');
$post->setSummary($this->getPostSummary());
$post->setContent($this->getPostContent());
$post->setAuthor($this->getReference('user-john_admin'));
$post->setCategory($this->getReference('category-Dolorem'));
$post->addTag($this->getReference('tag-consectetur'));
$post->addTag($this->getReference('tag-imperdiet'));
$post->addTag($this->getReference('tag-facilisis'));
$manager->persist($post);
$this->setReference('post-6', $post);
$manager->flush();
}
示例4: setCategory
/**
* {@inheritDoc}
*/
public function setCategory(\AppBundle\Entity\Category $category = NULL)
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'setCategory', [$category]);
return parent::setCategory($category);
}