dqp21271 2012-05-02 17:56
浏览 55
已采纳

Drupal - 通过URL获取节点的正文文本?

I'm trying to create a function to retrieve and display just the Body field of a Drupal node, based on a given URL.

Currently, I've extended the functionality of the standard Drupal RSS to do a detection method. This will happen if you enter the following url: http://mysite.com/rss.xml/page=54

That last part is critical - it tells what node ID to load from. As far as code goes, I've modified the node_feed() function in /modules/node/node.module to do the following:

if (stristr($nids, 'page=') !== FALSE) {
 $nid = substr($nids, stripos($nids, 'page=') + 5);
 $result = NULL;

 if ((string)(int)$nid === $nid) {
  $result = db_result(db_query("SELECT `nid` FROM {node} WHERE `nid` = %s AND `type` =  'flashnode'", $nid));
 }

 if ($result) {
   $item = node_load($result);
   print($item->body);
 }
 exit;
}

While this works, we're worried about it for two reasons:

1) Do the results cache? This is a very heavy-load page that will be called a lot.

2) Is there an "official" way to do this? One that uses modules with caching, instead of a semi-hacky workaround?

Thanks in advance for any guidance. -Tom

  • 写回答

1条回答 默认 最新

  • douxiu6835 2012-05-02 20:41
    关注

    You should definitely not be hacking apart the RSS feed in order to create a URL that returns a node's body. You should create a very simple custom module: http://drupal.org/developing/modules

    The Drupal module system is lets you set up a url so that something like /fetch_body/1234 calls the fetch_body() function with $nid=1234 as the parameter. As for caching, you have a lot of options in your custom module. The most obvious would be to use cache_get() and cache_set() to do simple caching on your own based on the node ID.

    What version of Drupal are you using? I would highly recommend the book Pro Drupal Development, just make sure to get the edition that matches your drupal version.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改