doushouhe7072 2019-06-20 15:20
浏览 85

如何修复Drupal 7中node_load()导致的'EntityMalformedException'?

I've been trying to load a node from the database which I have the nid for but I keep getting an EntityMalformedException. This is the error I get:

EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7947 of C:\Apache24\htdocs\devrevolution\includes\common.inc).

I'm using Drupal 7.67, MySQL 5.7, and Apache 2 on Windows 10. node_load() is used hundreds of times in this project with no problems, but somehow in this function I can't get it to properly return a node without throwing this exception. I'm aware that EntityFieldQuery is the preferred way to retrieve a node from the database in Drupal 7, but when I tried the following, it retrieved nothing from the database.

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
      ->propertyCondition('type', 'study')
      ->fieldCondition('field_sname', 'value', $study_name, '=')
      ->addMetaData('account', user_load(1))
      ->execute();

The field exists and is populated in the field_sname table with the nid attached but it doesn't retrieve the node for some reason.


I have checked to make sure the node actually exists in the node table, and then used the following to retrieve the nid from the database. I've made sure the node has a revision id as well, as that was causing problems for others. This code works to get the correct nid, but when it gets to node_load($nid) it throws the exception. I know that node_load is causing the error because without the line, there are no errors.

function get_study_information($study_name)
{
    // Retrieve the node nid with the study name from the database
    $query = db_query(
        'SELECT n.nid AS nid '. 
        'FROM {node} n '.
        'WHERE title = :studyname AND type = :study',
        array(':studyname' => $study_name,
              ':study' => "study"));

    $nid = $query->fetchAssoc()['nid'];
    $node = node_load($nid);
    return $node;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作