My index.php file exist in public_html/myapp/files directory,And i am trying to use library which exist in same directory public_html/myapp/files. But I am getting error
Class 'SightengineClient' not found in
/home/public_html/myapp/files/index.php on line 7
Where i am wrong ?
Here is my code
namespace Tests;
use SightengineClient;
$client = new SightengineClient('myapikey', 'secretkey');
$output = $client->check(['nudity'])->set_url('https://d3m9459r9kwism.cloudfront.net/img/examples/example7.jpg');
echo "<pre>";print_R($output);
Using the use kewyord will not include the class if you are not managing your project with composer(generating the autoload ) will you can require the file in this way :
require_once('path to SightengineClient file');
$t = new SightengineClient;
Using require_once will ensure that you are include only one time the
file .
Related
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';
Ok so I have been learning vanilla php and wanted to delve into making use of packages. so I tried implementing fabpot\Goutte to the teeth.
I did install the package using Composer and placed the src code in the root folder where the Composer-generated files sit. As I run the script, I get an initializing class not found error.
How do I get around with this? I have followed the instructions and it's making me crazyyyyyyyyyyyy
Code I got:
<?php
use Goutte\Client;
// Initialize object
$client = new Client();
// Issue GET request to URI
$crawler = $client->request("GET", "http://www.symfony.com/blog");
$client->getClient()->setDefaultOption("config/curl".CURLOPT_TIMEOUT, 60);
// Navigate the client through the use of links
$link = $crawler->selectLink("Security Advisories")->link();
$crawler = $client->click($link);
// Extract data
$crawler->filter("h2 > a")->each(function($node) {
print $node->text()."\n";
});
?>
The error I am getting:
Fatal error: Class 'Goutte\Client' not found in **line 6**
On top of your script.. You need to include composer's autoloader like this:
require __DIR__ . "/vendor/autoload.php";
I am integrating google spreadsheet in my project. I have to save form data into google spreadsheet.
For this i am using asimqt php-google-spreadsheet-client library.
I have single form on site that form is submitting using ajax. For this i have written function in function.php.
Getting error when initializing object of DefaultServiceRequest class.
Error: Fatal error: Class 'Google\Spreadsheet\DefaultServiceRequest' not found
require '/vendor/autoload.php';
use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
function spreadsheet_feeds()
{
$access_tok = 'xyz-token';
$serviceRequest = new DefaultServiceRequest($access_tok); // Getting error
ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
}
add_action( 'wp_ajax_nopriv_spreadsheet_data', 'spreadsheet_feeds' );
add_action('wp_ajax_spreadsheet_data','spreadsheet_feeds');
Any help why this error is occurring because class is already include using "use" statement ?
This seems to be an issue with the location of your vendor folder.
Make sure that the vendor folder is accessible by the file
Considering your folder hierarchy to be
-wp-content
--themes
---your-theme
----functions.php
If you have your vendor folder in your-theme/vendor then in your functions.php
you should write
require 'vendor/autoload.php';
and if vendor is in the root directory of WP make sure you traverse back to the root folder using something like :
require __DIR__ .'/../../../../vendor/autoload.php';
Just replace require '/vendor/autoload.php'; to require_once('vendor/autoload.php');
Just now I tried this here for you myself and it works.
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.
I was trying to test this Google Datastore Library for PHP. I have copied the GDS folder to my application's root directory and created a php file in the same root directory. When i run the code I'm getting this error Fatal error: Class 'GDS\Gateway' not found in /home/personal/SampleApp/datastore.php on line 2
datastore.php
<?php
$obj_client = GDS\Gateway::createGoogleClient('AppID', 'xxxx#developer.gserviceaccount.com', 'appKeyFile.p12');
$obj_gateway = new GDS\Gateway($obj_client, 'AppID');
$obj_book_store = new GDS\Store($obj_gateway, 'Book');
$obj_book = new GDS\Entity();
$obj_book->title = 'Romeo and Juliet';
$obj_book->author = 'William Shakespeare';
$obj_book->isbn = '1840224339';
$obj_book_store->upsert($obj_book);
?>
Is there anything I'm missing here ?
Did you use composer to pull in the library? If not you'll need to either write your own autoload script or add the following lines
include_once 'src/GDS/Entity.php';
include_once 'src/GDS/Gateway.php';
include_once 'src/GDS/Store.php';