I need to use https://github.com/maxmind/GeoIP2-php extension in Yii version 1 project (i.e. without namespace concept project).
Tried: $reader = new \GeoIp2\Database\Reader('/path/to/GeoIP2-City.mmdb');
The main.php has following code:
'import' => array(
'common.extensions.*',
)
Also common/extensions folder has the above extension under 'GeoIP2' folder.
But no luck. The error is:
Fatal error: Class 'GeoIp2\Database\Reader' not found in
.....Controller.php on line ..
Any ideas.
Got it working by doing the following:
In main.php, I added the following lines:
Yii::setPathOfAlias('GeoIp2',Yii::getPathOfAlias('common.extensions.GeoIp2.src'));
In controller-action, I modified the line:
$reader = new GeoIp2\Database\Reader('/path/to/GeoIP2-City.mmdb');
If anyone knows any other way, please let us know.
It may help later.
Related
I'm implementing this package following the instructions found here.
In my config, as instructed, I have
'wiki'=>[
'class'=>'asinfotrack\yii2\wiki\Module',
'processContentCallback'=>function($content) {
//example if you want to use markdown in your wiki
return Parsedown::instance()->parse($content);
}
]
I am getting an error on wiki/content/view?id=index: Class 'app\modules\wiki\Module' not found - what have I missed?
It looks like there is wrong class namespace used in the package by the developer i.e app\modules\wiki\Module instead of asinfotrack\yii2\wiki\Module
to fix this issue without changing the code in the vendor you can set the classmap on top of the project config file( common.php or main.php ) like this
Yii::$classMap['app\modules\wiki\Module'] = VENDOR_PATH.'/toasinfotrack/yii2-wiki/Module.php';
More details about classmapping in Yii2 can be found here
I want to include the Threema library in my Codeigniter project, but I have trouble doing it. This is the library.
I followed the instructions, created an autoload with composer, but I don't know how to make it work. I have an helper that looks like this :
require_once APPPATH . "libraries/Threema/vendor/autoload.php";
//define your connection settings
$settings = new ConnectionSettings(
'*xxxxx',
'xxxxxx'
);
$publicKeyStore = new Threema\MsgApi\PublicKeyStores\File("pathTo/threema_key.php");
$connector = new Connection($settings, $publicKeyStore);
I have the error :
Class 'ConnectionSettings' not found
I tried to do as the guide by using the keyword "use" but that doesn't work either :
use Threema\MsgApi\Connection;
use Threema\MsgApi\ConnectionSettings;
use Threema\MsgApi\Receiver;
What is the simple way to install this library in a CodeIgniter environment ?
try to change this line
require $SERVER['DOCUMENT_ROOT'] ./'libraries/Threema/vendor/autoload.php';
When creating a Client in Evernote sandbox sample:
$client = new \Evernote\Client($token, $sandbox);
I'm getting following error:
Fatal error: Class 'Psr\Log\NullLogger' not found in C:\xampp\htdocs\evernote\evernote-cloud-sdk-php\src\Evernote\Client.php on line 156
I know, this is because of missing: Psr\Log, files but I do not know where I should add them?
I don't want to use composer because I'm not sure if I will be able to use it in production. Anyway the settings is as follows: https://github.com/evernote/evernote-cloud-sdk-php/blob/master/composer.json
Does anyone know how to add the Psr\Log into Evernote PHP SDK API please?
Thank you!
After some testing I found the solution as follows:
download ZIP file of: Psr\Log, from: https://github.com/php-fig/log
save folder: Psr, into folder: evernote-cloud-sdk-php/src
change file: autoload.php, within folder: evernote-cloud-sdk-php/src, as follows:
Add new value into array:
$namespaces = array(
'EDAM',
'Thrift',
'Evernote',
'Psr'
);
Create new function:
function psrAutoload($className, $lastNsPos)
{
return genericAutoload($className, $lastNsPos);
}
Seems to be working so far, hope it will help someone to safe time.
I am unable to install nusoap to my existing laravel 5 application. Ive done the following:
Created a new Folder in App/Http/Controllers/ - namend "Soap" - and copied the libary into it.
use
composer dump-autoload
So i am able to use
use nusoap_client;
But i am always getting an error:
Class 'App\Http\Controllers\nusoap_client' not found
I thought that laravel automatically load all classes from the "app" directory, but how can i use it here?
Tried with:
$wsdl = "test.xx/_vti_bin/lists.asmx?wsdl";
$client = new nusoap_client($wsdl, true);
Thanks for any help!
Just add these lines to your controller:
include 'nusoap.php';
use nusoap_client;
As a simple way, you can add a backslash in front of nusoap_client, like this:
$client = new \nusoap_client($wsdl, true);
So I have the Paypal REST API installed ( https://github.com/paypal/rest-api-sdk-php ) with Composer in my_drupal_module/lib/Drupal/ and now I want to use the namespaces in a function in my module. I understood that I need something like xautoload ( https://drupal.org/project/xautoload ) to do that so I tried something like:
$payer = new \Drupal\vendor\PayPal\Api\Payer;
with and without the first slash, and with and without parentheses at the end but it didn't work. I added:
require DIR . '/lib/Drupal/vendor/autoload.php';
but still nothing so I commented it. Meanwhile I found this: https://drupal.org/node/1976206 that explains this issue but it is unclear to me what exactly to write in hook_xautoload() or direct registration for the setup that I have. Can someone please help?
Nevermind. I solved it. Thanks to proloy03 who gave me the idea: https://drupal.org/node/2096621
You don't need xautoload to load the classes and namespace just implement hook_init to require it like so:
function my_module_init() {
require __DIR__ . '/vendor/autoload.php';
}
and then in your function write:
$payer = new PayPal\Api\Payer();
and it all works.
With xautload you can do something like this...
In mymodule.module
function mymodule_libraries_info() {
'paypal' => array(
'name' => 'PayPal SDK',
'xautoload' => function($adapter) {
$adapter->composerJson('composer.json');
}
}
Declaring this allow you to use the namespace. Like
use PayPal\Api\Amount;
Check xautoload.api.php
Your assumption that you need XAutoload to use the Paypal API installed by Composer is wrong.
The only thing you need to make any code installed by Composer available is to include the Composer autoloader in your code execution path when you need any of the provided classes. The easiest form of this is to simply require the Composer autoloader in the very first index.php (or whatever Drupal uses) file that answers every request (possibly instantiating more Drupal classes, modules and stuff).
Once the code execution comes to your own code, the autoloading allows your code to include all the classes you included with Composer.
How to use the code? Don't invent your own namespace for the existing code, it will not work. "\Drupal\vendor\PayPal\Api\Payer" sounds pretty wrong to me, I suspect the correct namespace is "\PayPal\Api\Payer". And yes, that file does indeed exist. So you have to use that.
If it still does not work, complaining the class could not be loaded, then the Composer autoloader file is not included in your scripts code path.