我意识到这个问题几乎肯定是通过前面问题中的八百万个建议中的一个来解决的,但是我找不到问题或解决方案。
我在CodeIgniter 3中有一个PHP7.3应用程序,我使用的是Algolia搜索客户端PHP。
我已通过npm安装并设置了composer requirements.
中没有这些请求。
composer.json
{
"name": "jess/wcr-local",
"autoload": {
"psr-4": {
"Jess\\WcrLocal\\": "src/"
}
},
"authors": [
{
"name": "",
"email": ""
}
],
"require": {
"algolia/algoliasearch-client-php": "^3.3",
"phpclassic/php-shopify": "^1.1"
}
}composer.lock
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "84220834899a78925602aeeef0ab3571",
"packages": [
{
"name": "algolia/algoliasearch-client-php",
"version": "3.3.0",
"source": {
"type": "git",
"url": "https://github.com/algolia/algoliasearch-client-php.git",
"reference": "aa491a36579d8470c99c15064a79b6b4f83e85e4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/algolia/algoliasearch-client-php/zipball/aa491a36579d8470c99c15064a79b6b4f83e85e4",
"reference": "aa491a36579d8470c99c15064a79b6b4f83e85e4",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"php": "^7.2 || ^8.0",
"psr/http-message": "^1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
"fzaninotto/faker": "^1.8",
"phpunit/phpunit": "^8.0 || ^9.0",
"symfony/yaml": "^2.0 || ^4.0"
},
"suggest": {
"guzzlehttp/guzzle": "If you prefer to use Guzzle HTTP client instead of the Http Client implementation provided by the package"
},
"bin": [
"bin/algolia-doctor"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-2.0": "2.0.x-dev"
}
},
"autoload": {
"files": [
"src/Http/Psr7/functions.php",
"src/functions.php"
],
"psr-4": {
"Algolia\\AlgoliaSearch\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Algolia Team",
"email": "contact@algolia.com"
}
],
"description": "Algolia Search API Client for PHP",
"keywords": [
"algolia",
"api",
"client",
"php",
"search"
],
"support": {
"issues": "https://github.com/algolia/algoliasearch-client-php/issues",
"source": "https://github.com/algolia/algoliasearch-client-php/tree/3.3.0"
},
"time": "2022-07-06T14:08:05+00:00"
},
{
"name": "phpclassic/php-shopify",
"version": "v1.1.23",
"source": {
"type": "git",
"url": "https://github.com/phpclassic/php-shopify.git",
"reference": "5bc3d3affeb4fcb0c5d7a1233ff58d1b503bad80"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpclassic/php-shopify/zipball/5bc3d3affeb4fcb0c5d7a1233ff58d1b503bad80",
"reference": "5bc3d3affeb4fcb0c5d7a1233ff58d1b503bad80",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"php": ">=5.6"
},
"require-dev": {
"phpunit/phpunit": "^5.5"
},
"type": "library",
"autoload": {
"psr-4": {
"PHPShopify\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"authors": [
{
"name": "Tareq Mahmood",
"email": "tareqtms@yahoo.com"
}
],
"description": "PHP SDK for Shopify API",
"homepage": "https://github.com/phpclassic/php-shopify",
"keywords": [
"php",
"sdk",
"shopify"
],
"support": {
"issues": "https://github.com/phpclassic/php-shopify/issues",
"source": "https://github.com/phpclassic/php-shopify/tree/v1.1.23"
},
"time": "2022-07-14T15:39:59+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"support": {
"source": "https://github.com/php-fig/http-message/tree/master"
},
"time": "2016-08-06T14:39:51+00:00"
},
{
"name": "psr/log",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001",
"reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001",
"shasum": ""
},
"require": {
"php": ">=8.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Log\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for logging libraries",
"homepage": "https://github.com/php-fig/log",
"keywords": [
"log",
"psr",
"psr-3"
],
"support": {
"source": "https://github.com/php-fig/log/tree/3.0.0"
},
"time": "2021-07-14T16:46:02+00:00"
},
{
"name": "psr/simple-cache",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/simple-cache.git",
"reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/simple-cache/zipball/764e0b3939f5ca87cb904f570ef9be2d78a07865",
"reference": "764e0b3939f5ca87cb904f570ef9be2d78a07865",
"shasum": ""
},
"require": {
"php": ">=8.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\SimpleCache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interfaces for simple caching",
"keywords": [
"cache",
"caching",
"psr",
"psr-16",
"simple-cache"
],
"support": {
"source": "https://github.com/php-fig/simple-cache/tree/3.0.0"
},
"time": "2021-10-29T13:26:27+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}在我的类中使用(类的其余部分如预期的那样)
<?php
use Algolia\AlgoliaSearch\InsightsClient;
class Click_model extends CI_Model {
function conversion() {
if ( !class_exists('InsightsClient') ) die('There is no hope!');
}
}发布于 2022-07-16 18:23:23
请确保您的文件名和类名必须匹配。此外,请尝试使用编程标准,因为类有一个--在定义类名时始终使用pascal大小写,例如FileManager、AlgoliaSearch等
最后,您没有导入要扩展的类CI_Model。如果这是上面提到的包中的类,那么通过将/CI_model放在import语句的末尾来确保它是导入的。
发布于 2022-08-28 15:59:47
最后,我发现这是一个与自动驾驶有关的问题。通过添加下面的第一行,use语句将正确解析,使控制器可以使用它。
require FCPATH."/vendor/autoload.php";
use Algolia\AlgoliaSearch\SearchClient;https://stackoverflow.com/questions/73006590
复制相似问题