gpt4 book ai didi

php - 如何连接到在 cake php v3.x 的 salesforce 中创建为自定义字段的 Heroku connect 表

转载 作者:行者123 更新时间:2023-11-29 13:54:43 25 4
gpt4 key购买 nike

我正在尝试通过 CakePHP 3 连接 Heroku 连接表。出于某种原因,当我尝试连接名称以“__c”结尾的表时出现以下错误

 PHP Fatal error:  Call to a member function newEntity() on boolean

之前,我解决了我在 CakePHP 中遇到的基本连接问题 Heroku Connect with Cakephp v3.0.12 形式。

这样我就可以连接一个表名中没有“__c”的表。从错误消息中,我了解到由于某种原因我的蛋糕应用程序无法连接到我想要连接的表。

在我的 App/Model/Table/someFieldTable.php 中,我有

 public function initialize(array $config)
{
parent::initialize($config);
$this->table('salesforce.some_field__c');
$this->displayField('name');
$this->primaryKey('id');
}

我的 tableController.php 中也有以下内容

$somefield = $this->someField->newEntity();
// variables are assigned to $somefield
if($this->someField->save($someField)){
// error handling here
}

我对 CakePHP 和 Heroku connect 还是个新手。如果有人知道如何在 CakePHP 中使用后缀“__c”连接这些字段(表),请帮助我。

最佳答案

使用 TableRegistry 类是一个有效的答案,下面是让 Controller 中的 Autowiring 表正常工作的正确方法:

如您所知,您的文件命名方案不正确,但这不是使用 Heroku 格式化表名的完整解决方案。您在 $this->table() 中的条目不应该是带点的数据库的命名空间,因为数据库是通过您正在查询的当前连接(很可能是 app.php 中定义的默认数据源)附加的。整个修复包括:

// 1. Change the file name to the correct scheme: SomeFieldTable.php

// 2. In order for the controller to autowire the table, you must correctly
// name the controller file as well: SomeFieldController.php

// 3. Change the table name within SomeFieldTable.php to the appropriate
// name: 'some_field_c'

public function initialize(array $config)
{
parent::initialize($config);
$this->table('some_field__c');
$this->displayField('name');
$this->primaryKey('id');
}

// 4. Finally, in the controller, the table is accessed via the camel capsed name

class SomeFieldController extends AppController
{
public function getEndpoint()
{
$result_set = $this->SomeField->find()->all();
$this->set('result_set', $result_set);
}

public function saveEndpoint()
{
$new_some_field = $this->SomeField->newEntity($this->request->data);
if ($this->SomeField->save($new_some_field)) {
$this->set('new_some_field', $new_some_field);
} else {
$this->set('errors', $new_some_field->errors());
}
}
}

关于php - 如何连接到在 cake php v3.x 的 salesforce 中创建为自定义字段的 Heroku connect 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34429361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com