Arrays 数组_flip():只能翻转字符串和整数值!在DrupalDefaultEntityController中->;加载()
我最近将模块迁移到Drupal7(在PHP版本5.3.1上),现在出现以下错误:Arrays 数组_flip():只能翻转字符串和整数值!在DrupalDefaultEntityController中->;加载(),arrays,drupal,drupal-modules,php,Arrays,Drupal,Drupal Modules,Php,我最近将模块迁移到Drupal7(在PHP版本5.3.1上),现在出现以下错误: * Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\inclu
* Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
* Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
* Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
* Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
* Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
* Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
* Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
* Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of C:\Users\akulkarni\Desktop\xampp\htdocs\servicecasting\includes\entity.inc).
我还尝试将其他模块和核心升级到这里提到的最新版本
实体7.x-1.x-dev(2011年1月24日),
视图7.x-3.x-dev(2011年1月22日),
Drupal core 7.x-dev(2011年1月24日),
剖面图2 7.x-1.0-beta1,
参考7.x-2.x-dev(2011年1月14日),
ctools 7.x-1.0-alpha2
我无法找出到底是什么导致了这个错误
编辑:
根据,
array_flip()以翻转顺序返回数组,即trans中的键
变为值和来自trans的值变为键
请注意,trans的值必须是有效键,即它们必须是整数或字符串。如果出现以下情况,将发出警告:
值的类型错误,并且所讨论的键/值对不会
被激怒了
我已经完成了var\u转储($ids)代码>在entity.inc中第178行之前($passed\u ids=!empty($ids)?array\u flip($ids):FALSE;
)
在我看来,键/值对的格式总是正确的(?)
您正在使用插入模块吗?看
当涉及到像这样的特定错误时,我认为您最好在搜索问题队列,而不是询问问题队列。我在周末遇到了相同的数组翻转错误,试图将自定义模块升级到Drupal 7。问题是嵌套数组被传递到DrupalDefaultEntityController,但它需要一个简单的整数或字符串数组。在我的例子中,我将一个嵌套数组传入EntityFieldQuery,而它只需要一个整数数组
为了更好地跟踪调用DrupalDefaultEntityController的代码,请尝试在entity.inc的第178行之前插入以下内容:
drupal_set_message(var_export(debug_backtrace(), TRUE));
。。。或者,最好安装模块并尝试插入以下内容:
dpm( debug_backtrace() );
此错误最常见的原因是使用带有数组作为参数的something_load()函数。这不再受支持,因为现在需要使用load_multiple()函数
D6中的示例:
<?php
// Using array with the id was already discouraged in D6 but still worked.
$user = user_load(array('uid' => 1));
$user = user_load(array('name' => 'admin'));
?>
Drupal 7:
<?php
// Argument to a load() function *must* be a single id
$user = user_load(1);
// Querying for another attribute is a bit more complex.
// Note that using reset(user_load_multiple() directly is not E_STRICT compatible.
$users = user_load_multiple(array(), array('name' => 'admin'));
$user = reset($users);
?>
在我们使用最新的页面标题模块时发现了类似的问题。现在,我们只是禁用了模块,它清除了错误
请参阅:这里有一个简单的解决方案:)
编辑settings.php
文件并添加此行
error_reporting(0);
当您使用非实体id数组的数组作为第二个参数调用entity_load时,也会发生这种情况-请参阅并了解原因。当您使用Organic groups field access(Organic groups 7.x-1.3)时,问题会出现
您通常可以禁用该子模块,除非您使用OG执行字段级访问控制
谢谢你为我写的帖子!,很长时间以来,我在Drupal7中遇到了这个问题,我可以解决这个问题。底线
“对于任何类型的实体,不要将数组值传递给array_flip,
例如:如果试图加载和实体用户_load()或字段_collection_item_load()以加载字段集合项,请仅传递字符串中的值,而不是数组本身。”
谢谢 良好使用示例:
<?php
$user=user_load(arg(1));
$username=$user->name;
print strtolower(preg_replace('/[^a-zA-Z0-9\-]/si' , '-' , $username));
?>
这可能是错误编码的问题(例如加载无效实体或在Drupal7中运行一些旧的Drupal6代码):
- 如果您有任何自定义模块,请仔细检查代码是否存在常见错误
- 无效使用
- 将加载对象的数组传递给实体_load()
- 检查和,它提供了在Drupal7中使用实体的正确方法
- 如果您使用的是contrib模块,请找到针对它的正确错误,并应用补丁(如果可用)或提出新的补丁
故障排除:
- 您可以通过调用并打印
print\r(debug\u backtrace())
来尝试转储回溯
- 使用scm工具返回到正常工作的位置,并比较更改,以便最终找到问题所在(例如,
gitk
,git log--patch
,等等)
- 请在更新后使用模块查找代码中的错误(例如,
drush--contrib--no empty--upgrade7x coder review
)
- 安装以通过跟踪日志或逐步调试跟踪您的问题
或者,您可以通过定义以下临时挂钩来调试代码:
/**
* Implements hook_watchdog().
*/
function foo_watchdog($log_entry) {
if ($log_entry['type'] == 'php' && $log_entry['severity'] <= WATCHDOG_WARNING) {
// Old school
var_dump(debug_backtrace()); // Optionally add: exit();
// Devel: Log the backtrace into temporary file: drupal_debug.txt
// Locate via: $ drush eval "echo file_directory_temp() . '/drupal_debug.txt'"
function_exists('dd') && dd(debug_backtrace());
}
}
/**
*实现hook_watchdog()。
*/
函数foo\u watchdog($log\u条目){
如果($log\u entry['type']=='php'&&$log\u entry['severity']]我在错误地尝试通过node\u load\u multiple($nids)加载多个节点时也收到了此消息,其中$nids不是节点ID数组
例如,使用EntityFieldQuery的结果,调用node_load_multiple('result['node'])而不是node_load_multiple(array_Key('result['node'])。当Drupal上出现此类错误时,我的建议是首先检查管理面板中的“最近日志消息”列表:
这一页对我有很多帮助
提示:有时,不仅要查看最后一个错误,还要查看它前面的警告和注意消息。其中一个消息的详细信息通常包含解决问题的重要提示。您是否将模块或站点迁移到drupal 7?如果是自定义模块,代码在哪里?您也应该尝试关闭模块,直到警告消失,以缩小范围。某些参数错误。是的,我已将模块迁移到Drupal 7。但错误在entity.inc文件中,该文件是Drupal 7的核心文件。关于上面的var_dump输出:否,在k中ey/值对格式不正确。数组\u flip函数可以翻转数组,如数组(0=>'a')/**
* Implements hook_watchdog().
*/
function foo_watchdog($log_entry) {
if ($log_entry['type'] == 'php' && $log_entry['severity'] <= WATCHDOG_WARNING) {
// Old school
var_dump(debug_backtrace()); // Optionally add: exit();
// Devel: Log the backtrace into temporary file: drupal_debug.txt
// Locate via: $ drush eval "echo file_directory_temp() . '/drupal_debug.txt'"
function_exists('dd') && dd(debug_backtrace());
}
}