0
我正在用TYPO3的Extbase創建示例博客。我的博客有很多帖子,一篇文章有很多評論。問題是我在創建帖子時收到了錯誤消息:「給update()的修改對象不是該存儲庫管理的類型(Myext \ Myblog \ Domain \ Model \ Blog)。」創建TYPO3 Extbase關係不起作用
請看看我的博客的show.html:
...
<p style="text-align: center">
<f:link.action action="new" controller="Post" arguments="{blog:blog, post: post}"class="btn btn-primary">
Add Post
</f:link.action>
</p>
...
new.html從帖子的模板:
<f:layout name="Default" />
This template displays a NEW form for the current domain object.
If you modify this template, do not forget to change the overwrite settings
in /Configuration/ExtensionBuilder/settings.yaml:
Resources:
Private:
Templates:
New.html: keep
Otherwise your changes will be overwritten the next time you save the extension in the extension builder
<f:section name="main">
<div class="container">
<div class="clearfix"></div>
<h1 style="color: black; text-align: center">New Post</h1>
<f:flashMessages />
<f:render partial="FormErrors" arguments="{object:Post}" />
<f:form action="create" enctype="multipart/form-data" name="newPost" object="{newPost}" >
<f:render partial="Post/FormFields" arguments="{blog:blog, post:post}"/>
<f:form.submit value="Create new" class="btn btn-primary" style="margin:10px 0" />
</f:form>
</div>
</f:section>
從後部分FormFields.html:
<label for="title">
<f:translate key="tx_myblog_domain_model_post.title" /> <span class="required">(required)</span>
</label><br />
<f:form.textfield property="title" style="width: 100%" /><br />
<label for="content">
<f:translate key="tx_myblog_domain_model_post.content" />
</label><br />
<f:form.textarea property="content" cols="60" rows="15" style="width: 100%"/><br />
最後PostController中:
class PostController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
protected $postRepository = NULL;
public function injectPostRepository(\MyExt\Myblog\Domain\Repository\PostRepository $postRepository)
{
$this->postRepository = $postRepository;
}
/**
* action list
*
* @return void
*/
public function listAction()
{
$posts = $this->postRepository->findAll();
$this->view->assign('posts', $posts);
}
public function showAction(\MyExt\Myblog\Domain\Model\Post $post)
{
$this->view->assign('post', $post);
}
public function newAction(\MyExt\Myblog\Domain\Model\Blog $blog, \MyExt\Myblog\Domain\Model\Post $post = NULL)
{
$this->view->assign('blog',$blog);
$this->view->assign('post',$post);
}
public function createAction(\MyExt\Myblog\Domain\Model\Post $newPost)
{
$this->addFlashMessage('The object was created. Please be aware that this action is publicly accessible unless you implement an access check. See http://wiki.typo3.org/T3Doc/Extension_Builder/Using_the_Extension_Builder#1._Model_the_domain', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
$today = new \DateTime('now');
$newPost->setPostDate($today);
$this->postRepository->add($newPost);
$this->objectManager->get('MyExt\\myblog\\Domain\\Repository\\BlogRepository')->update($blog);
$this->redirect('list');
}