0

I'm using the googleAds API, but when I include a class that I need in my function it still shows me an error :

Error: Class 'TargetingIdeaSelector' not found
File: C:\wamp64\www\projet\app\Model\Keyword.php
Line: 26

I'm including it like this :

include 'C:\wamp64\www\projet\vendors\googleads\googleads_php_lib\src\Google\AdsApi\AdWords\v201710\o\TargetingIdeaSelector.php';

And further in my function, I'm using this :

// Create selector.
$selector = new TargetingIdeaSelector();

Bringing me the error above. Is there something else to do to use a class previously included ?

SnowYou
  • 39
  • 6
  • Replaced all '\' with '\\' still throwing the same error, it's still able to locate the folder to include but can't instantiate a class – SnowYou Jun 04 '18 at 08:53
  • You've been told in a previous question (https://stackoverflow.com/questions/50605057/how-to-include-adwords-in-a-cakephp-model-to-be-able-to-use-its-classes) to use composer https://github.com/googleads/googleads-php-lib this lib features composer. You still have not learned how to use composer or how to implement your own auto-loader. https://www.sitepoint.com/autoloading-and-the-psr-0-standard/ – floriank Jun 04 '18 at 10:13
  • I tried to use the autoloader, but like I answered, I just can't understand how I need to adapt it to works in my case. I added "require": { "googleads/googleads-php-lib" : "*" } in my composer.json file. But I don't know how to link everything together. That's why I tried with include and because it found the folder, I thought it could work that way. – SnowYou Jun 04 '18 at 10:57
  • What is the class name defined in the TargetingIdeaSelector.php file? Is it "TargetingIdeaSelector"? Remember that capitalization matters. – Mr Glass Jun 04 '18 at 11:25
  • The class is in a namespace. Have you `use`d the namespace so that PHP knows where to find it? This is in *addition to* including the file with the implementation (whether that happens manually or through the autoloader). – Greg Schmidt Jun 04 '18 at 18:23
  • I included the php file "TargetingIdeaSelector.php", used the namespace Google\AdsApi\AdWords\v201710\o and required the autoload.php, did I mixed actions ? – SnowYou Jun 05 '18 at 14:05

1 Answers1

1

Got a fix from someone better than me :

 require_once __DIR__ . '../../Vendor/autoload.php';

use Google\AdsApi\AdWords\v201710\o\TargetingIdeaSelector;
use Google\AdsApi\AdWords\v201710\o\LanguageSearchParameter;
use Google\AdsApi\AdWords\v201710\o\RelatedToQuerySearchParameter;
use Google\AdsApi\AdWords\v201710\cm\Language;
use Google\AdsApi\AdWords\v201710\cm\Paging;

It was all about using the good namespaces, I just was overloaded by the quantity of files in my project and couldn't figure out the solution out of my mess. My bad :)

SnowYou
  • 39
  • 6