Welcome Guest, Not a member yet? Register   Sign In
Include external library
#9

[eluser]ephlodur[/eluser]
Hello heenji and all,
Thanks a lot for your help.
I have manage to load the class with minor changes to the file provided by heenji.
The content of the "lib" directory for PHPRtfLite is located in application/libraries/PHPRtfLite
the file below "PHPRtfLite.php" is located in the directory application/libraries.
Code:
<?php
if (!defined('BASEPATH')) {exit('No direct script access allowed');}
class PHPRtfLite
{
        /**
        * Constructor
        *
        * @param string $class class name
        */
        $rtf = NULL;
        function __construct()
        {


        $dir = dirname(__FILE__);
        require_once $dir . '/PHPRtfLite/PHPRtfLite.php';

        ini_set('include_path',
        ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries/PHPRtfLite/');

                if ($rtf)
                {
                require_once (string) $rtf . EXT;
                log_message('debug', "PHPRtfLite Class $rtf Loaded");
                }
                else
                {
                log_message('debug', "PHPRtfLite Class Initialized");
                }
        }

        /**
        * PHPRtfLite Class Loader
        *
        * @param string $class class name
        */
        function load($rtf)
        {
                require_once (string) $rtf . EXT;
                log_message('debug', "PHPRtfLite Class $rtf Loaded");
        }
}
?>
and in the controller the code below was used to test that it was working
Code:
public function testrtf()
        {

         $this->load->library('PHPRtfLite/PHPRtfLite');
         PHPRtfLite::registerAutoloader();
         $rtf = new PHPRtfLite();
         $sect = $rtf->addSection();
         $sect->writeText('<i>hello<b>world</b></i>.', new PHPRtfLite_Font(12), new PHPRtfLite_ParFormat(PHPRtfLite_ParFormat::TEXT_ALIGN_CENTER));

         // save rtf document
         $rtf->save('hello.rtf');
         echo 'create ok,and download <a href="'.base_url().'hello.rtf">here</a>';

        }


Messages In This Thread
Include external library - by El Forum - 02-27-2012, 01:17 PM
Include external library - by El Forum - 02-29-2012, 07:50 AM
Include external library - by El Forum - 02-29-2012, 09:53 AM
Include external library - by El Forum - 02-29-2012, 11:20 AM
Include external library - by El Forum - 02-29-2012, 11:46 AM
Include external library - by El Forum - 02-29-2012, 12:04 PM
Include external library - by El Forum - 02-29-2012, 12:11 PM
Include external library - by El Forum - 02-29-2012, 01:29 PM
Include external library - by El Forum - 03-01-2012, 02:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB