How to use Amazon s3 as a Codeigniter library? - php

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).

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()

Codeigniter DB Language extension not working

I'm trying to use this extension
But it gives me the following error when loading the library:
Unable to load the requested class: Language
Also if I write MY_Language instead, it gives me the following error:
Fatal error: Class 'CI_Language' not found in C:\wamp\www\ckphp\application\libraries\MY_Language.php on line 79
I am using WAMP and CI v. 2.2.0
Thanks!
I figured it out myself after some more researching...
Apparently the language class is not even in the library folder, but in core folder, meaning it should be placed in the core application/core folder. Also the name is not CI_Language, but CI_Lang, meaning the file name has to be MY_Lang (if MY_ is your prefix). The last thing to change in the extension is
parent::CI_Language();
to
parent::__construct();
and everything should work fine!
Usage:
$this->lang->load('set', 'language'); // To load a language
$this->lang->line('key'); // to display the text
or simply
lang('key'); // if using the language helper
Hope this will help others in the future!
I made a GIST for latest CodeIgniter 3.1.X including with migration to create the database structure
https://gist.github.com/cyberfly/885b320fdf914ae15f7316b22cc72f32

How to access external library in magento?

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

unable to load Assetes class with MY_Assetes in same directory

i have one third party asset library in my application folder, i am extending that library with MY_Assets library both are in same application/library directory, but when loading its giving error Unable to load the requested class: Assets, i want to add some extra features in library by extending it so if developer of main library make any update nothing effect to mine extension
Place the file in application folder and need to include the code manually then extends from it.
See the below code that I uses for extending the Facebook connect for Codeigniter.
include(APPPATH.'libraries/facebook/facebook.php');
class Fb_connect extends Facebook{
//my coding here
}
Here I have a folder named facebook inside the libraries folder for facebook related dowloaded files and FB_connect.php is my library file it is in application /libraries folder and fb_connect class that inherits from Facebook class.

Using ProcessBuilder in a Silex Project

I am wanting to use the Symfony\Component\Process\ProcessBuilder class and can see that it is included as part of the Silex codebase within the vendors folder. I am using the Silex phar file and assume that because I can readily instantiate other Symfony components like Request, Response and so on that it will correctly locate the file to include when I use the full namespace.
$foo = new Symfony\Component\HttpFoundation\Request(); //works fine
However, when I try and create and instance of it using:
$foo = new Symfony\Component\Process\ProcessBuilder(); //class not found
It gives me a class not found error. Does anyone know why this is and how I can use this class from the Silex phar without including the component seperately within my project?
It looks like the Process Symfony component is not included in the compiled Silex phar file.

Categories