Drupal程序启动代码函数

Drupal程序之开始,如果我们要写一个Drupal程序,那么下面两行代码是必不可少的:

require_once ‘./includes/bootstrap.inc’;
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

这两行Drupal代码可以说是Drupal的启动按钮,drupal_bootstarp负责Drupal的启动工作。

今天写了一个Druapl Statistics的函数,忘记以前的Drupal的启动代码了。

下面就是Drupal增加Node Statistics的的函数:

Drupal程序之开始,如果我们要写一个Drupal程序,那么下面两行代码是必不可少的:

require_once ‘./includes/bootstrap.inc’;
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

这两行Drupal代码可以说是Drupal的启动按钮,drupal_bootstarp负责Drupal的启动工作。

今天写了一个Druapl Statistics的函数,忘记以前的Drupal的启动代码了。

下面就是Drupal增加Node Statistics的的函数:

<?php

require_once ‘./includes/bootstrap.inc’;
//drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

function statistics_incr($nid) {
  $nid = (int)$nid;
  if ($nid) {
    drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);
    if (variable_get(‘statistics_count_content_views’, 0)) {
      // We are counting content views.
      // A node has been viewed, so update the node’s counters.
      db_query(‘UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, t    imestamp = %d WHERE nid = %d’, time(), $nid);
    }
  }
}
 

Leave a Reply

Your email address will not be published. Required fields are marked *