skip to Main Content

I realize this problem is almost certainly solved by one of the eight million suggestions in previous questions of the same problem, but I can’t find the problem or the solution.

I have a PHP 7.3 app in CodeIgniter 3. I am using the Algolia Search Client PHP API.

  1. I have installed via npm and set up composer requirements.
  2. I have updated composer to require the package
  3. I have verified the presence of the file
  4. I am using namespaces (copied and pasted from Algolia’s documentation and verified via PHPstorm that the path is correct)
  5. I am not using PHP short tags in these files, nor does Algolia
  6. Using the PHP function class_exists() I can verify other classes in my app exist, but nothing in the vendor directory seems to (indicating a composer problem)
  7. I tried using require() instead of use — did not resolve the issue
  8. I have restarted Apache, ran composer dump-autoload, and updated all of the vendor packages via npm (not necessarily in that order)
  9. There is nothing from these requests in the PHP Error Log

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": "[email protected]"
                }
            ],
            "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": "[email protected]"
                }
            ],
            "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"
}

use in my class (the rest of the class functions as expected)

<?php

use AlgoliaAlgoliaSearchInsightsClient;

class Click_model extends CI_Model {
   function conversion() {
       if ( !class_exists('InsightsClient') ) die('There is no hope!');
   }
}

2

Answers


  1. Chosen as BEST ANSWER

    Eventually I figured out this was an issue related to autoload. By adding the first line below, the use statement resolves correctly, making it available to the Controller.

    require FCPATH."/vendor/autoload.php";
    use AlgoliaAlgoliaSearchSearchClient;
    

  2. Please make sure your file name and name of the class must match. Plus, please try using standards of programming as class has one i.e. Always use pascal case when defining the name of class e.g. FileManager, AlgoliaSearch etc

    lastly, you are not importing class CI_Model which you are extending. if this is the class in the above mentioned package then trying to make sure it is getting importing by placing /CI_model in the end of import statement

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search