如何在cakePhp模型中包含adWords以能够使用其类? [英] How to include adWords in a cakePhp Model to be able to use its classes?

查看:87
本文介绍了如何在cakePhp模型中包含adWords以能够使用其类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在CakePHP应用程序中使用Google的AdWords API。
我需要在我已经建立的现有模型中的某个位置搜索关键字。

I'm trying to use AdWords API from Google in a cakePHP application. I need to search for keywords at some point inside an already existing model that I made.

这个想法是,如果我还没有获得关键字,则可以获取有关该关键字的信息我的数据库。
但是当我需要使用某些类别的adWords时,出现此错误:

The idea is to get information about the keyword if I dont' already got it in my database. But when I need to use some classes of adWords, I'm getting this error :


错误:找不到类'TargetingIdeaSelector'

文件:C:\wamp64\www\projet\app\Model\Keyword.php

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

行:36

这是我拥有的代码的想法:

Here is an idea of the code I have :

public function getsuggestions($word, $someData) {

        if(!empty($word) && $word != '') {
            $data = $this->find('all', array(
                'conditions' => array('Keyword.mot_saisi' => $word)
            ));
            if(!empty($data)) { 
                $motcles = split(",",$data['0']['Keyword']['result'],11);
                $motcles['10'] = $word;

                return $motcles;
            }
            else {
                // Create selector.
                $selector = new TargetingIdeaSelector(); //Here is the error
                $selector->requestType = 'IDEAS';
                $selector->ideaType = 'KEYWORD';
                $selector->requestedAttributeTypes = array('KEYWORD_TEXT', 
'SEARCH_VOLUME',
                    'CATEGORY_PRODUCTS_AND_SERVICES');
                // Create language search parameter (optional).
                // The ID can be found in the documentation:
                //   
https://developers.google.com/adwords/api/docs/appendix/languagecodes
                // Note: As of v201302, only a single language parameter is 
allowed.
                $languageParameter = new LanguageSearchParameter();
                $french = new Language();
                $french->id = 1002;
                $languageParameter->languages = array($french);
                // Create related to query search parameter.
                $relatedToQuerySearchParameter = new 
RelatedToQuerySearchParameter();
                $relatedToQuerySearchParameter->setQueries(array($word));
                $selector->searchParameters[] = 
$relatedToQuerySearchParameter;
                $selector->searchParameters[] = $languageParameter;
                // Set selector paging (required by this service).
                $paging = new Paging();
                $paging->setStartIndex(0);
                $paging->setNumberResults(10);
                $selector->setPaging($paging);

                // Make the get request.
                $content = $targetingIdeaService->get($selector);

[...]

我想我的adWords类不包括在内模型,但是如何包含所有adWords内容,以便可以在模型中使用多个类?

I guess adWords classes are not included in my model, but how can I include all the adWords content so that I can use multiple classes inside my model ?

(我的项目中直接有googleads-php-lib)

(I have googleads-php-lib directly inside my project)

编辑

这是确切的解决方案:

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;


推荐答案


(我有googleads -php-lib直接在我的项目中)

(I have googleads-php-lib directly inside my project)

您需要告诉自动加载器在哪里找到它并使用在文件中使用语句。

You need to tell the auto loader where to find it and use the use statement inside your file.

  • http://php.net/manual/en/language.namespaces.importing.php
  • https://getcomposer.org/doc/01-basic-usage.md#autoloading
  • PHP namespaces and "use"
  • Custom code management with the Composer auto loader?
  • PHP adding custom namespace using autoloader from composer
  • https://jtreminio.com/2012/10/composer-namespaces-in-5-minutes/

这篇关于如何在cakePhp模型中包含adWords以能够使用其类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆