2015-10-16 25 views
0

我有控制器索引操作的代碼。如何在數據庫中設置和保存數據在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 model方法將數據保存到數據庫中。當我轉儲但不保存到數據庫時,當前設置'測試...'。 我正在使用typo3 7.6

回答

0

您必須將您的對象傳遞給將其保存到數據庫的存儲庫。您需要使用的方法不同取決於對象是否已經存在,或者它是新的。

對於新對象,你必須使用add()方法:

$this->pagesRepository->add($pagesResults); 

而對於現有的使用update()

$this->pagesRepository->update($pagesResults); 
+0

我已經嘗試過這種 $這個 - > pagesRepository->更新($ pagesResults); 但它只是設置值,並不保存到數據庫。 我是否需要在我的倉庫中定義update()? – NK143

+0

如果您的存儲庫擴展'Repository',則不需要。嘗試注入'PersistenceManager'並將對象傳遞給'update()'調用'$ this-> persistanceManager-> persistAll();'。 – marian0

+0

你能告訴我什麼是PersistenceManager和我們爲什麼使用它? 我是typo3的新手,所以不太瞭解它。 – NK143

相關問題