Thursday, June 30, 2016

有谁懂 php 的?问个问题(有包子)

http://www.mitbbs.com/article_t/SanFrancisco/34457927.html

发信人: treeq (没事干,刷刷题), 信区: SanFrancisco
标  题: 有谁懂 php 的?问个问题(有包子)
发信站: BBS 未名空间站 (Thu Jun 30 22:56:52 2016, 美东)



有谁懂 php 的?问个问题。

下面一段程序,print 那个 $formattedresponse 的时候,总是说amazon_access_key
没有 configure之类的, 类似的另外一个程序,写法类似,print $formattedresponse
的时候,就有结果。

还有,我不太懂php 里, variable 是怎么定义的, 定义了$amazon_access_key 后,
我试图在之后print, 但都说该变量没有define. 为什么? 我如果在之前,刚定义好了
的那里print, 仿佛问题更大。为什么?怎么把一开始设定的variable 打印出来呢?

这些 amazon keys 的 configure 到底哪里出错了?

多谢!

接触php 不多,觉得这个语言有点神.



ini_set('memory_limit', '10000M');

class GatherData extends Command
{
    private $rtKey = 'xxxxxx';
    private $amazon;
    private $amazon_access_key = null;
    private $amazon_secret_key = null;
    private $amazon_associate_tag = null;
  
    print $amazon_access_key;

    protected function configure()
    {
        $this
            ->setName('api:gatherdata')
            ->setDescription('Processes a file with title names and
retrieves their XXX details from APIs')
        ;
    }

    /**
     * setParameters
     * An array of keys so we can access our AWS services.  This is
configured via the
     * parameters.yml file and loaded in console
     *
     * @param array Parameters
     *
     * @return null
     */
    public function setParameters($params)
    {
        if (!isset($params['amazon_access_key']) || !isset($params['amazon_
secret_key']) || !isset($params['amazon_associate_tag']))
            throw new Exception("Missing AWS parameters.  Please configure
your parameters.yml file");

        $this->amazon_associate_tag = $params['amazon_associate_tag'];
        $this->amazon_secret_key = $params['amazon_secret_key'];
        $this->amazon_access_key = $params['amazon_access_key'];

        print $amazon_access_key;
    }

    public function initialize(InputInterface $input, OutputInterface $
output)
    {
        $conf = new GenericConfiguration();
        $conf
            ->setCountry('com')
            ->setAccessKey($this->amazon_access_key)
            ->setSecretKey($this->amazon_secret_key)
            ->setAssociateTag($this->amazon_associate_tag);

        $this->amazon = new ApaiIO($conf);

    }

    private function getAmazon($title)
    {
        $search = new Search();
        $search->setCategory('XXX');
        $search->setKeywords($title);
        $formattedResponse = $this->amazon->runOperation($search);
       
        print $formattedResponse;






No comments:

Post a Comment