如何在typo3中设置和保存数据库中的数据
how to set and save data in database in typo3
我有控制器索引操作的代码。
public function indexAction() {
$this->initContentObject();
$titleforSocial = $GLOBALS['TSFE']->page['title'];
$uidforSocial = $GLOBALS['TSFE']->page['uid'];
$pidforSocial = $GLOBALS['TSFE']->page['pid'];
echo "title: ".$titleforSocial . " uid: ". $uidforSocial . " pid:" .$pidforSocial;
$elementUid = $this->cObj->data['_LOCALIZED_UID'] ? $this->cObj->data['_LOCALIZED_UID'] : $this->cObj->data['uid'];
$buttonResults = $this->contentRepository->findByIdentifier($elementUid);
$pagesResults = $this->pagesRepository->findByIdentifier($elementUid);
$button_text = $buttonResults->getButtontext();
$page_title = $pagesResults->setTitle('testing...');
var_dump($button_text);
$pagesResultsz = $this->pagesRepository->findByIdentifier($elementUid);
var_dump($pagesResultsz);
exit;
$button_text = $this->cObj->data['buttonText'];
$this->view->assign("button_text", $button_text);
}
我的主要问题是如何使用模型的set方法将数据保存到数据库中。当我转储但不将其保存到数据库时,当前设置 'testings...' 。
我正在使用 typo3 7.6
您必须将您的对象传递到存储库,存储库将其保存到数据库中。您需要使用的方法因对象已存在或新对象而异。
对于新对象,您必须使用 add()
方法:
$this->pagesRepository->add($pagesResults);
现有的一种用途update()
:
$this->pagesRepository->update($pagesResults);
我有控制器索引操作的代码。
public function indexAction() {
$this->initContentObject();
$titleforSocial = $GLOBALS['TSFE']->page['title'];
$uidforSocial = $GLOBALS['TSFE']->page['uid'];
$pidforSocial = $GLOBALS['TSFE']->page['pid'];
echo "title: ".$titleforSocial . " uid: ". $uidforSocial . " pid:" .$pidforSocial;
$elementUid = $this->cObj->data['_LOCALIZED_UID'] ? $this->cObj->data['_LOCALIZED_UID'] : $this->cObj->data['uid'];
$buttonResults = $this->contentRepository->findByIdentifier($elementUid);
$pagesResults = $this->pagesRepository->findByIdentifier($elementUid);
$button_text = $buttonResults->getButtontext();
$page_title = $pagesResults->setTitle('testing...');
var_dump($button_text);
$pagesResultsz = $this->pagesRepository->findByIdentifier($elementUid);
var_dump($pagesResultsz);
exit;
$button_text = $this->cObj->data['buttonText'];
$this->view->assign("button_text", $button_text);
}
我的主要问题是如何使用模型的set方法将数据保存到数据库中。当我转储但不将其保存到数据库时,当前设置 'testings...' 。 我正在使用 typo3 7.6
您必须将您的对象传递到存储库,存储库将其保存到数据库中。您需要使用的方法因对象已存在或新对象而异。
对于新对象,您必须使用 add()
方法:
$this->pagesRepository->add($pagesResults);
现有的一种用途update()
:
$this->pagesRepository->update($pagesResults);