简体   繁体   中英

Getting error in add Bundle in Vendor Folder in Symfony2

Bundle Name : Open tok ( i downloaded it from github )

i put that folder in Vendor Folder of Symfony( project name\\vendor\\OpenTok\\OpenTok\\and all files and folders here )

in AppKernel.php

<?php

 use Symfony\Component\HttpKernel\Kernel;
 use Symfony\Component\Config\Loader\LoaderInterface;

 class AppKernel extends Kernel
 {
     public function registerBundles()
     {
        $bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new OpenTokBundle\OpenTokBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new AdminBundle\AdminBundle(),
        new SiteBundle\SiteBundle(),
        new WSBundle\WSBundle(),
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
        $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    }

    return $bundles;
   }

  public function registerContainerConfiguration(LoaderInterface $loader)
  {
      $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
   }
}

in app\\autoload.php

 <?php

  use Doctrine\Common\Annotations\AnnotationRegistry;
  use Composer\Autoload\ClassLoader;
  /**
  * @var ClassLoader $loader
  */
  $loader = require __DIR__.'/../vendor/autoload.php';
  AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
  $loader->add('OpenTok' , __DIR__.'/..vendor/OpenTok');
  return $loader;

 ?>

Composer.json

  "require": {
        "php": ">=5.3.9",
        "symfony/symfony": "2.8.*",
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "~2.0", 
       "opentok/opentok": "dev-master"
   },

This above code gives me error :

Fatal error: Class 'OpenTokBundle\\OpenTokBundle' not found

now how can i use opentok Bundle in my all other files ? Please help me. I am new to symfony

Your issue is due to the slash.
It should be $loader->add('OpenTok' => __DIR__.'/../vendor/OpenTok'); as in the other line (although I'm not sure the actual path would be correct).

That being said you should actually download and manage the package using composer as it has dependencies that won't be included by just downloading the repository.

To do this:

  1. Delete the $loader->add('OpenTok' => __DIR__.'/..vendor/OpenTok'); line from your autoload
  2. Add "opentok/opentok": "^2.3.2" or the version you want to download to your "require" key in your composer.json
  3. Run composer update opentok/opentok .

The package and classes should now be available in your application and, when you require a newer version, you can manage it all through composer rather than needing to download the package by hand (along with all dependencies).

I think you should manage all using composer, and you need to install the library opentok/opentok and the bundle for symfony joos/open-tok-bundle so in your composer.json ...

"require": {
    "php": ">=5.3.9",
    "symfony/symfony": "2.8.*",
    "doctrine/orm": "^2.4.8",
    "doctrine/doctrine-bundle": "~1.4",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~5.0",
    "sensio/framework-extra-bundle": "^3.0.2",
    "incenteev/composer-parameter-handler": "~2.0",
    "joos/open-tok-bundle": "2.3.x-dev", 
    "opentok/opentok": "dev-master"
   },

Run composer install

And in your AppKernel.php

<?php

 use Symfony\Component\HttpKernel\Kernel;
 use Symfony\Component\Config\Loader\LoaderInterface;

 class AppKernel extends Kernel
 {
     public function registerBundles()
     {
        $bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new Joos\OpenTokBundle\JoosOpenTokBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new AdminBundle\AdminBundle(),
        new SiteBundle\SiteBundle(),
        new WSBundle\WSBundle(),
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
        $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    }

    return $bundles;
   }

  public function registerContainerConfiguration(LoaderInterface $loader)
  {
      $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
   }
}

From this url https://github.com/djoos/JoosOpenTokBundle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM