So I just started to learn Redis and tried to install it for PHP using this link :- https://github.com/nrk/predis
I installed it via composer and then ran :-
require 'autoload.php';
$client = new Predis\Client(array('host' => "127.0.0.1", "port" => 6379, array("prefix" => "php:")));
$client->set("string:k", "something");
However, this generates error :-
Fatal error: Uncaught Error: Class 'Predis\Configuration\Options' not found in /Library/WebServer/Documents/redis/2/src/Client.php on line 74
Error: Class 'Predis\Configuration\Options' not found in /Library/WebServer/Documents/redis/2/src/Client.php on line 74
What is wrong here?
You have to register Predis Autoloader like this
require __DIR__ . '/vendor/autoload.php'; //autoload vendor see https://getcomposer.org/doc/01-basic-usage.md#autoloading
$client = new Predis\Client(array('host' => "127.0.0.1", "port" => 6379, array("prefix" => "php:")));
$client->set("string:k", "something");
Related
I have a slight problem when trying to use woocommerce rest api.
I have next structure:
...../plugins/woocommerce/
save-parsed-products-ajax.php
vendor/
automattic/
WooCommerce/
HttpClient/...
Client.php
...
autoload.php
save-parsed-products-ajax.php
<?php
$consumer_key = 'here_is_my_key'; // here was my real valid consumer key
$consumer_secret = 'here_is_secret'; // here was my real consumer secret
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'https://www.mywebsite.ru/', // here was my real website url
$consumer_key,
$consumer_secret,
[
'wp_api' => true,
'version' => 'wc/v3',
'query_string_auth' => true // Force Basic Authentication as query string true and using under HTTPS
]
);
print_r($woocommerce->get('products'));
?>
output
Fatal error: Uncaught Error: Class 'Automattic\WooCommerce\Client' not found in
/var/www/u1111184/data/www/mywebsite.ru/wp-content/plugins/woocommerce/save-parsed-products-
ajax.php:11
Stack trace: #0 {main} thrown in /var/www/u1111184/data/www/mywebsite.ru/wp-
content/plugins/woocommerce/save-parsed-products-ajax.php on line 11
I found this video that did same steps I did but my is not working. Could anyone help?
You can try following code
require_once ('..\vendor\autoload.php');
use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;
$woocommerce = new Client(
'https://www.mywebsite.ru',
'ck_****************************************',
'cs_****************************************',
[
'wp_api' => true,
'version' => 'wc/v3',
'query_string_auth' => true
]
);
print_r($woocommerce->get('products'));
Error will remain same until we do not use exception class
I use woocommerce rest api for managing products and other things. Here are the step I follow in order to do it:
Step:1 Goto woocommerce settings->advance->
Legacy API
Step:2 Create REST API
Step:3 Code
$autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( is_readable( $autoloader ) ) {
require_once $autoloader;
}
use wordpress\CorePhp\WooCommerce\Client;
$woocommerce = new Client(
'http://localhost/wordpress',
'ck_44d1f5a2a193274e4dfba6ee7ec764cedd345000',
'cs_6be79b8bd5ec0dbb1828309db24ae338abce44b3',
[
'wp_api' => true,
'version' => 'wc/v2'
]
);
?>
Fatal error: Uncaught Error: Class
'wordpress\CorePhp\WooCommerce\Client' not found in
C:\xampp\htdocs\wordpress\CorePhp\getproducts.php:9 Stack trace: #0
{main} thrown in C:\xampp\htdocs\wordpress\CorePhp\getproducts.php on
line 9
i solve above issue there is issue with not install autoload in project folder that's why it give error here are the code which working proper :
<?php
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;
$woocommerce = new Client(
'http://localhost/wordpress',
'your consumer key',
'your secret key',
[
'wp_api' => true,
'version' => 'wc/v2'
]
);
/*var_dump($woocommerce);*/
?>
i was following alex's how to build a shopping cart lesson and everything's working fine. but then i dont know what im doing wrong so i get this error :
Fatal error: Uncaught Error: Class 'maimana\App' not found in /Applications/MAMP/htdocs/maimana/bootstrap/app.php:13 Stack trace: #0 /Applications/MAMP/htdocs/maimana/public/index.php(3): require() #1 {main} thrown in /Applications/MAMP/htdocs/maimana/bootstrap/app.php on line 13
bootsrap/app.php :
<?php
use Respect\Validation\Validator as v;
use maimana\App as MyApp;
use Slim\Views\Twig;
use Illuminate\Database\Capsule\Manager as Capsule;
session_start();
require __DIR__ . '/../vendor/autoload.php';
$app = new MyApp;
$container = $app->getContainer();
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'maimana',
'username' => 'rdp46',
'password' => 'littlelion4696',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
require __DIR__ . '/../app/routes.php';
Myapp/App.php :
namespace maimana;
use DI\ContainerBuilder;
use DI\Bridge\Slim\App as DiBridge;
class App extends DiBridge{
protected function configureContainer(ContainerBuilder $builder)
{
$builder->addDefinitions([
'settings.displayErrorDetails' => true,
]);
$builder->addDefinitions(__DIR__ . '/container.php');
}
}
anyone know what's going on?
Rename the Myapp directory to maimana (note case) and then update your composer.json to autoload the maimana namespace.
i.e. ensure that your composer.json has:
"autoload": {
"psr-4": {
"maimana\\": "maimana/"
}
}
This assumes that the maimana directoryis in the root of your project where the composer.json file is. Once you have changed composer.json, you need to run composer dumpautoload for the changes to take effect.
This is required because there is a one to one mapping between directory name that the PHP file is in and the namespace for the class in that PHP file. As the namespace in your App.php is maimana, the directory needs to be maimana.
So basically I just installed Phalcon 2.0 on my ubuntu machine, with apache2, mysql and all the stuff installed. I went straight into the documentation of Phalcon to get me started. After following the exact steps from their tutorial, I got this error:
Fatal error: Class 'Users' not found in /var/www/html/phalcon/tutorial/app/controllers/SignupController.php on line 14
I think it may be related to namespacing of classes and stuff like that, but I wasn't able to figure it out so far.
Looks like you didn't register your folders properly. I add a resume of my code to give you an idea.
File index.php
use Phalcon\Mvc\Micro;
use Phalcon\Events\Manager as EventsManager;
define('APP_DIR', dirname(__DIR__) .'/');
try {
$config = require APP_DIR .'config/config.php';
require APP_DIR .'config/loader.php';
...
} catch (Exception $e) {}
File config.php
return new Phalcon\Config([
'application' => [
'environment' => 'development',
'controllers' => APP_DIR .'controllers/',
'library' => APP_DIR .'library/',
'models' => APP_DIR .'models/',
'plugins' => APP_DIR .'plugins/',
'routes' => APP_DIR .'routes/',
'logs' => APP_DIR .'logs/',
'base_uri' => '/',
'debug' => false
]
]);
File loader.php
<?php
$loader = new \Phalcon\Loader;
// Register directories
$loader->registerDirs([
$config->application->controllers,
$config->application->library,
$config->application->models,
$config->application->plugins,
])->register();
// Composer autoloader
require_once APP_DIR .'vendor/autoload.php';
This should resolve any class specified in config folders.
This is the php file named upload.php in ec2 server
require 'vendor/autoload.php';
use Aws\S3\S3Client;
$client = S3Client::factory(array(
'key' => 'aws-secret-key',
'secret' => 'aws-very-secret-pass',
));
$dir = '/home/user/movies/history';
$bucket = 'my-unique-bucket';
$keyPrefix = '';
$options = array(
'params' => array('ACL' => 'public-read'),
'concurrency' => 20,
'debug' => true
);
$client->uploadDirectory($dir, $bucket, $keyPrefix, $options);
When I execute the upload.php file in terminal returns fatal error like this,
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/home/kaya/Resimler/transferet/): failed to open dir: No such file or directory' in /var/www/html/vendor/aws/aws-sdk-php/src/Aws/S3/Sync/UploadSyncBuilder.php:47
Stack trace:
#0 /var/www/html/vendor/aws/aws-sdk-php/src/Aws/S3/Sync/UploadSyncBuilder.php(47): RecursiveDirectoryIterator->__construct('/home/user/movie...', 12800)
#1 /var/www/html/vendor/aws/aws-sdk-php/src/Aws/S3/S3Client.php(557): Aws\S3\Sync\UploadSyncBuilder->uploadFromDirectory('/home/user/movie...')
#2 /var/www/html/upload_dir.php(21): Aws\S3\S3Client->uploadDirectory('/home/user/movie...', 'my-unique-bucket', '', Array)
#3 {main}
thrown in /var/www/html/vendor/aws/aws-sdk-php/src/Aws/S3/Sync/UploadSyncBuilder.php on line 47
Normally I can upload files clearly with php sdk except uploadfolder function. I couldnt find where is false. My php sdk version is 2.7.
I figured it out. It works on local server like xampp or something, doesnt work on remote server.