[英]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方法將數據保存到數據庫。 當我轉儲但不將其保存到數據庫時,當前設置為“測試...”。 我正在使用typo3 7.6
您必須將對象傳遞到存儲庫,然后將其保存到數據庫。 您需要使用的方法因對象已存在或是新對象而異。
對於新對象,您必須使用add()
方法:
$this->pagesRepository->add($pagesResults);
對於現有的一種使用update()
:
$this->pagesRepository->update($pagesResults);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.