【问题标题】:FLOW3 definitive guide: can't save blog in databaseFLOW3 权威指南:无法将博客保存在数据库中
【发布时间】:2013-08-23 16:48:09
【问题描述】:

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

我的博客应该被创建并保存在数据库中,但事实并非如此。数据库的配置是正确的(FLOW3 已成功创建表和学说迁移/更新),代码看起来正确(从 FLOW3 定义指南 GIT 存储库复制)。

有人有类似的问题吗?

这是我的来自 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';
    }

如果我不够清楚,我将感谢任何帮助并提供更多信息。

提前谢谢

【问题讨论】:

    标签: typo3-flow


    【解决方案1】:

    TYPO3 FLOW 自 2.0 起不再保留 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();
            }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 1970-01-01
      • 1970-01-01
      • 2010-10-08
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多