Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在typo3中设置和保存数据库中的数据_Php_Typo3_Typo3 6.2.x - Fatal编程技术网

Php 如何在typo3中设置和保存数据库中的数据

Php 如何在typo3中设置和保存数据库中的数据,php,typo3,typo3-6.2.x,Php,Typo3,Typo3 6.2.x,我有控制器索引操作的代码 public function indexAction() { $this->initContentObject(); $titleforSocial = $GLOBALS['TSFE']->page['title']; $uidforSocial = $GLOBALS['TSFE']->page['uid']; $pidforSocial = $GLOBA

我有控制器索引操作的代码

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);
    }
我的主要问题是如何使用模型的集合方法将数据保存到数据库中。当前的一个在我转储时设置“testings…”,但不将其保存到数据库。
我使用的是typo3 7.6

您必须将对象传递到存储库,存储库将其保存到数据库中。需要使用的方法因对象已存在或是新对象而异

对于新对象,必须使用
add()
方法:

$this->pagesRepository->add($pagesResults);
对于现有的一个,请使用
update()


我已经尝试过这个$this->pagesRepository->update($pagesResults);但它只是设置值,而不是将其保存到数据库中。我是否也需要在我的存储库中定义update()?如果您的存储库扩展了
存储库
,则不必这样做。尝试注入
PersistenceManager
并在将对象传递到
update()
调用
$this->PersistenceManager->persistAll()之后。您能告诉我什么是PersistenceManager以及我们为什么使用它吗?我对typo3不太熟悉,所以对它了解不多。基本上,它是一个与数据库通信的对象。但现在我有点困惑。你使用的是TYPO3 Flow还是其他TYPO3系列产品?我编辑了标签,是关于TYPO3 CMS而不是Flow或Neos的。
$this->pagesRepository->update($pagesResults);