我希望能够将节点ID传递给路径并生成RTF文件。我在加载库时遇到问题。我正在使用Libraries 2方法。错误是:
PHP Fatal error: Class 'PHPRtfLite' not found in [redacted]/sites/all/modules/custom/ain_export/ain_export.module on line 22 request_id="245a0131-9519-4fa9-a512-3b60d0b91ad8"
所以我一直在确保这些文件应该在哪里。在我的/ sites / all / libraries目录中,我有一个名为'phprtflite'的文件夹,设置如下:
-- phprtflite
----PHPRtfLite.php
下面是我的代码,现在根据下面的评论进行编辑,以便在我的回调中加载库。我仍然得到错误,除了现在第41行。似乎没有加载库?
<?php
/**
* Implements hook_libraries_info().
*/
function ain_export_libraries_info() {
$libraries['phprtflite'] = array(
'name' => 'PHPRtfLite',
'vendor url' => 'http://sourceforge.net/projects/phprtf/',
'download url' => 'http://sourceforge.net/projects/phprtf/',
'files' => array(
'php' => array('PHPRtfLite.php'),
),
);
return $libraries;
}
/**
* Implements hook_menu().
*/
function ain_export_menu() {
$items = array();
$items['admin/ain_export/%'] = array(
'title' => 'Export Node',
'page callback' => 'ain_export_page',
'page arguments' => array(2),
'access arguments' => array('access administration pages'),
);
return $items;
}
// spit out node
function ain_export_page($nid) {
// load library
libraries_load('phprtflite');
// register PHPRtfLite class loader
PHPRtfLite::registerAutoloader();
if (isset($nid) ) {
try {
$rtf = new PHPRtfLite();
// set page properties
$rtf->setMargins(2.54, 2.54, 2.54, 2.54);
$rtf->setPaperFormat(PHPRtfLite::PAPER_LETTER);
// define fonts
$fontH1 = new PHPRtfLite_Font(16, 'Arial', '#000000');
$fontH2 = new PHPRtfLite_Font(14, 'Arial', '#000000');
$fontP = new PHPRtfLite_Font(12, 'Arial', '#000000');
// vertical space
$formatH1 = new PHPRtfLite_ParFormat();
$formatH1->setSpaceAfter(8);
$formatH2 = new PHPRtfLite_ParFormat();
$formatH2->setSpaceAfter(6);
$formatP = new PHPRtfLite_ParFormat();
$formatP->setSpaceAfter(3);
// page content
$node = node_load($nid); // load the node
// headline
$section = $rtf->AddSection();
$section->writeText($node->title, $fontH1, $formatH1);
// output file
$rtf->SendRtf( $nid . '.rtf' );
} catch (Exception $e) {
$error = $e->getMessage();
}
}
}