CakePHP with PHPRTFLite
How can I load the PHPRTFLite into a controller? I can load it into the view (using App::import('Vendor'....) and generate one file from the view currently. But under one action, I need to generate many files and save those on the server.
When I try to load it from the controller, it shows error messages like ...phprtf\FormHelper.php is not found. Why is it looking for FormHelper in the vendors/phprft folder?
If there is a way to load this into a model, please let me know as well.
开发者_运维问答Thank you very much for any help.
Best regards,
Tony.No reply so far, strange. So after some playing around, here is how I got it to working:
The answer I have posted earlier worked, but was not clean.
Here is a way better method to use PHPRTFLite with CakePHP 1.3.
Step 1) Put the phprtf folder in the vendors folder in CakePHP
So ls in vendors will look like this will look like this:
phprtf
shells
ls in ..\vendors\phprtf will look like this:
PHPRtfLite (Directory)
PHPRtfLite.php
Step 2) Open this file: ..\config\bootstrap.php and enter the following inside:
// The below lines will load the PHPRtfLite classes when required.
function loader($className){
$classFile = '../vendors/phprtf/' . str_replace('_', '/', $className) . '.php';
// check if file exists
if(file_exists($classFile)) {
require $classFile;
}
}
spl_autoload_register('loader');
So now you can use the PHPRtfLite classes in your Models to generate documents. I think they can be used from Controllers as well, but I haven't tried.
You can add more checks and so on to the code in the bootstrap.php if required.
I hope this helps someone. If you have comments, please let me know.
Cheers,
Tony.
精彩评论