跳转到主要内容

drupal 函数 module_invoke 函数说明

module_invoke函数就是为了激活一个模块的钩子函数,然后还可以把相关的参数传递到钩子函数里。

举例如下:

$wpage = module_invoke('ixi', 'load', array('wid'=>$wid), 'ixi_wpage');

上面的解释如下,调用ixi模块的ixi_load函数,同时把array('wid'=>$wid), 'ixi_wpage'这两个参数传递给ixi_load函数。

下面是ixi.module里的ixi_load函数的内容

{syntaxhighlighter brush:php} /** * Get inforation from table create by ixi project. * * @param array $condition * $condition = array('id'=>1); * @param string $table_name * @param int $pager_query * @param string $orderby * @param string $order * * @return array / false */ function ixi_load($condition=array(), $table_name, $pager_query=0, $orderby='', $order='DESC'){ $query = array(); $params = array(); $placeholder = '%d'; $sql = 'SELECT * FROM {'.$table_name.'}' ; foreach ($condition as $key=>$value){ if (is_string($value)) { $placeholder = "'%s'"; } $query[] = "$key=$placeholder"; $params[] = $value; } if (count($query)) { $sql .= ' WHERE '.implode(' AND ', $query); } if ($orderby) { $sql .= " ORDER BY $orderby ".$order; } if ($pager_query) { $result = 6">pager_query($sql, $pager_query, 0, NULL, $params); }else { $result = 6">db_query($sql, $params); } if (db_num_rows($result)) { while ($row=6">db_fetch_object($result)){ $items[] = $row; } return $items; }else{ return false; } } {/syntaxhighlighter}
文章分类