doyhq66282 2015-04-02 09:17
浏览 77

无法在Symfony2中加载第三方类

My main problem is, that i dont have access to Solarium (a third party libary) in my symfony2-project and I do not understand why. I have a symfony2 application and want to write my own Solr connector. Therefore I want to use Solarium. (IMPORTANT: I dont want to use other bundles for this)

First I installed it via composer

"require": {
        //...
        "solarium/solarium": "3.3.0.x-dev"
    }

Then i called:

php composer.phar install

php composer.phar update

Second i created a new directory for my connector in my bundle:

/src/COMPANY/ThatIsMyBundle/SolrSearch/

In this directory is my class SolrConnector.php

namespace COMPANY\ThatIsMyBundle\SolrSearch;

use Solarium\Client;
//use Solarium\Core\Client;

class SolrConnector {
        private $solr_client;
        function __construct($settings)
        {
            $solr_config = array(
                'endpoint' => array(
                    'protokolldb' => array(
                        'host' => $settings['solrHost'],
                        'port' => $settings['solrPort'],
                        'path' => $settings['path'],
                        'core' => $settings['core'],
                        'timeout' => $settings['timeout']
                    )
                )
            );
            $this->solr_client = new Client($solr_config);
        }

         /**
         * Check if Solr is on.
         */
       function executePing() {
            $ping = $this->solr_client->createPing();
            try {
                $this->solr_client->ping($ping);
                echo "Solr is fine.
";
            } catch (Exception $e) {
                echo "Solr is unaccessible. Look up whats wrong with Solr and restart this script.
 ".$e->getMessage();
            }
        }

    }

I got this error message from symfony:

Attempted to load class "Client" from namespace "Solarium" in "(my specific path to the project)/SolrSearch/SolrConnector.php line 32." Do you need to "use" it from another namespace?

What i have to do to use Solarium in my Symfony2 Bundle? I think it is a namespace/use/require problem. I googled it for hours... with no solution.

Things i tried:

adding

require('../vendor/autoload.php);

same error.

  • 写回答

1条回答 默认 最新

  • douganmo1121 2015-04-02 09:52
    关注

    When you use

    php composer.phar install
    

    it only install packages stored in composer.lock

    You need to run

    php composer.phar update
    

    to install new packages. It also clear and warm up symfony cache and autoloader

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么