How to access external library in magento? - php

I have a make a file in the magento root. like below
Foldername/pay.php
This files call api and work with some lib. when i call it through direct in the browser url.
I want to call this within magento function.
pay.php have a class and I add this file within a magento module file and make a object but it shows the error of object reference.
What should i do? Please suggest me.
Thanks in advance to all magento dev

put your library at [magento]/lib folder
for example your library is PhpExcel so you have to put it in [magento]/lib/PhpExcel
and include your library in magento file before call.
$includePath = Mage::getBaseDir(). "/lib/PhpExcel/Classes";
set_include_path(get_include_path() . PS . $includePath);
so you have create object of PhpExcel library to access it
$objPHPExcel = new PHPExcel();
for your reference download PhpExcel Export and check directory structure as well way to access external library in magento.
it create a object in [magento]\app\code\local\Conlabz\Mreport\controllers\Adminhtml\ExportController.php
hope this help you

Related

FPDF with Laravel

I am attempting to use the FPDF (http://www.fpdf.org/) PHP addon for my website that uses Laravel. I want to be able to dynamically create a PDF.
I have stored the libraries' files in the folder: '/public/vendor'.
This is what I have so far:
require $_SERVER['DOCUMENT_ROOT'] . '/vendor/fpdf/fpdf.php';
which works fine. However when I try to use the FPDF class using:
$pdf = new FPDF('P', 'pt', array(500,233));
I get the error: Class "'App\Console\Commands\FPDF' not found"
How can I fix this to use the library. I do not have access to command line so I have to manually import any folders or files.
Any help is greatly appreciated.
Update:: I do not have any access to the console so i cannot use composer. Any way to still do this?
Ideally if using Laravel, you should load it via composer the get it to work correctly.
If you do not have access to composer on the server, you could download the project, make sure you are running the same version of PHP as the server and run composer install fpdf/fpdf. Re-upload the composer.json, composer.lock and vendor folder.
https://packagist.org/packages/fpdf/fpdf
Try following code:
$pdf = new \Fpdf\Fpdf('P', 'pt', array(500,233));
FPDF is in the root namespace and you are within another namespace.
Highly recommend using https://github.com/mccarlosen/laravel-mpdf which can be installed via composer
It supports blade views and you can pass variables to it just like in view()

connect Braintree php sdk with yii

How can connect Braintree php sdk with yii.I have placed my all sdk files in component folder and calling main file in controller like:
include Yii::app()->basePath.'/components/braintree/lib/Braintree.php';
But this shows error to me include(Braintree_Configuration.php): failed to open stream: No such file or directory.Can anyone help me?
Standard practise to include third party library in Yii (1.x) is to put the code under protected/vendors directory, i.e. protected/vendors/braintree.
Then include this file in your code like this.
Yii::import('application.vendors.*');
require_once('braintree/lib/Braintree.php');
Make sure you have provided read permissions for braintree folder.

Integrating External Library into Wordpress

I'm trying to bring in an outside PHP library into my WP instance. I'd like to reference it in various plugins I'm creating, but am not sure how to include or instantiate it.
Specifically, I'm looking at the Library here: https://github.com/lobostome/FurryBear/wiki
I've tried a few different ways to include it without success, including using the SPLClassLoader command described here: https://github.com/lobostome/FurryBear/wiki/Installation
I'm not sure where to put the full library and then how to get it recognized by / loaded into WordPress so that it can be used.
Any help would be appreciated. Thanks
if your writing your own plugin you can put the FurryBear code in your plugin folder and then include it manually like
require_once 'SplClassLoader.php';
// Instantiate the SplClassLoader with the location directory of the source files.
$classLoader = new SplClassLoader(__DIR__ . '/src');
$classLoader->register();
Thanks. Basically, the require_once call to SplClassLoader.php they give on the wiki, and you mention above, is how it should be done. The problem was that the files were buried deep within the default build and were meant to be referenced from the same top level directory.
I moved the SplClassLoader.php file out as well as the src folder, putting both in the top level plugins folder and all worked as expected.
Thanks again.

PHPEXCEL in zend

I am working in zend and in admin panel I have to export my data I am using PHPExcel for doing this here is the folder structure
Admin
src
admin
Controller
view
Vendor
PhpExecl
standard
src
standard
static option
I am using $objPHPExcel = new \PHPExcel(); in static option
I am calling export function from my controller which is in the static option page but it is showing me 500 error
can you help
or if some body has a even better option then please post it
I just worked with that lib the other day, make sure you include the path to the Phpexcel library classes in your php include paths:
set_include_path(get_include_path().PATH_SEPARATOR.APPLICATION_PATH.'/your-path/phpexcel/Classes/');
The problem is related to autoload PHPExcel classes.
For sure a better option to avoid to have problems with autoload PHPExcel classes, and avoid to manual adding the classes in the include path, is to use MvlabsPHPExcel that gives an easy integration of PHPOffice/PHPExcel library into zend framework 2.

How to use Amazon s3 as a Codeigniter library?

I created a file called awslib.php and put it in the application/libraries folder. These are the contents of awslib.php:
<?php
class Awslib {
function Awslib()
{
require_once('sdk-1.5.6.2/sdk.class.php');
}
}
Also in the libraries folder is the PHP sdk as a folder named sdk-1.5.6.2.
On my home controller I am loading the library and instantiating the s3 class:
$this->load->library('awslib');
$s3 = new AmazonS3();
When I load my homepage I get this error:
Fatal error: Class 'AmazonS3' not found in /var/www/application/controllers/home.php on line 23
Why isn't it working?
Note: the problem isn't with s3, I can get it to work fine when I store it outside codeigniter and load the demo files that come with the sdk.
I'm assuming you're using the SDK for PHP directly. Most SDKs don't play nicely in CI unless wrapped up.
I highly recommend using the amazon-s3 library (or rather, the spark).

Categories