FLOW3权威指南:无法在数据库中保存博客

时间:2013-08-21 10:44:42

标签: typo3-flow

我正在做FLOW3权威指南:Part3: Controller

我的博客应该被创建并保存在数据库中,但事实并非如此。数据库的配置是正确的(FLOW3创建了表和doctrine成功迁移/更新),代码看起来正确(从FLOW3 definitve guide GIT repo复制)。

有没有人有类似的问题?

这是我在SetupController中的indexAction,它应该在数据库中创建博客:

   /**
     * Sets up a fresh blog and creates a sample post.
     *
     * @return void
     */
    public function indexAction() {
        $this->blogRepository->removeAll();
        $this->postRepository->removeAll();

        $blog = new \TYPO3\Blog\Domain\Model\Blog();
        $blog->setTitle('My Blog');
        $blog->setDescription('A blog about Foo, Bar and Baz.');
        $this->blogRepository->add($blog);

        $post = new \TYPO3\Blog\Domain\Model\Post();
        $post->setAuthor('John Doe');
        $post->setTitle('Example Post');
        $post->setContent('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
        $this->postRepository->add($post);

        return $blog->addPost($post) == true ? 'success' : 'error';
    }

如果我不够清楚,我将不胜感激,并会提供更多信息。

提前谢谢

1 个答案:

答案 0 :(得分:3)

自2.0以来,TYPO3 FLOW不再保留Safe Requests (like HTTP GET)的更改。

这意味着如果您想要在GET-Request中保留更改,则必须自己致电persistenceManager->persistAll()

class SetupController extends \TYPO3\Flow\Mvc\Controller\ActionController {


        /**
         * @Flow\Inject
         * @var \TYPO3\Flow\Persistence\PersistenceManagerInterface
         */
        protected $persistenceManager;

        //.... 

        public function indexAction() {
               //.... your code
               $this->persistenceManager->persistAll();
        }
}