I use this documentation for install algolia:
https://www.algolia.com/doc/api-client/symfony/setup/
this configuration is already done:
composer require algolia/algolia-search-bundle
And
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Algolia\AlgoliaSearchBundle\AlgoliaAlgoliaSearchBundle(),
);
configuration.yml:
algolia:
application_id: YOUR_APP_ID
api_key: YOUR_API_KEY
but I don't understand , I need a example for implementation in my project.
Please your help
1-) you should install algolia-search-bundle with Composer;
composer require algolia/algolia-search-bundle
2-) add line this -> Algolia\AlgoliaSearchBundle\AlgoliaAlgoliaSearchBundle() at app/AppKernel.php file into $bundles array.
3-)you should add your api keys at app/config/config.yml file;
algolia:
application_id: YOUR_APP_ID
api_key: YOUR_API_KEY
That's enough.
I have a new bundle MyBundle under
src/MyVendor/Bundle/MyBundle/
and in the default controller I wish to use class MyClass which resides in namespace called MyVendor\MyComponent
which is located under src/MyVendor/Component/MyComponent/src/MyVendor/MyComponent/MyClass.php
I've tried to do
use Symfony\Component\ClassLoader\UniversalClassLoader;
$myLoader = new UniversalClassLoader();
$myLoader->registerNamespace(
'MyVendor\\MyComponent\\',
__DIR__.'/../src/MyVendor/Component/MyComponent/src'
);
in app/autoload.php but I'm still getting the ClassNotFoundException error.
Either I'm missing something subtle, or my idea is completely wrong (wrong psr-0 dir structure) or should this be done solely via composer's autoload e.g.
"autoload": {
"psr-0": {
"MyVendor\\MyComponent\\":
"src/MyVendor/Component/MyComponent/src"
}
}
and
composer dump-autoload --optimize
In either case, I'd appreciate any help.
thank you
OK, I think I've figured it out:
registerNamespace should not have trailing \\ in the namespace
I need to add $myLoad->register();
so the whole thing looks like
use Symfony\Component\ClassLoader\UniversalClassLoader;
$myLoader = new UniversalClassLoader();
$myLoader->registerNamespace(
'MyVendor\\MyComponent',
__DIR__.'/../src/MyVendor/Component/MyComponent/src'
);
$myLoader->register();
I'd still like to see how to do this with the composer and dump-autoload
i'm trying to use registerPrefixes() in my app/autoload.php but i get the folowing error:
Fatal error: Class 'Symfony\Component\ClassLoader\UniversalClassLoader'
not found in C:\wamp\www\ProjetJidal\app\autoload.php on line 6
Here is my autoload.php:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->registerPrefixes(array(
'Html2Pdf_' => __DIR__.'/../vendor/html2pdf/lib',
));
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
i appreciate any help thanks !
instead of doing it that way in the past i have just used the unofficial port for composer compatibility.
php composer.phar require "ensepar/html2pdf":"dev-master"
This command will update your composer.json and install the needed lib and then the autoload.php doesnt have to be updated at all it will be loaded automatically.
I am trying to follow the tutorial ## but am running into an issue.
I am receiving the following exception:
Call to undefined method Symfony\Component\Config\Definition\Builder\NodeBuilder::fixXmlConfig() in DIR\vendor\jms\serializer-bundle\JMS\SerializerBundle\DependencyInjection\Configuration.php line 46
Does anyone know what is going on?
I have enabled both required bundles:
new JMS\SerializerBundle\JMSSerializerBundle($this),
new FOS\RestBundle\FOSRestBundle(),
I'm guessing that one of the bundles is not updated to 2.3 as of yet maybe?
If you use the dev-master branch for both dependencies you can get it up and running.
composer.json
"require": {
...
"friendsofsymfony/rest-bundle": "0.12.0",
"jms/serializer-bundle": "dev-master",
"jms/di-extra-bundle": "dev-master"
},
AppKernel.php
new JMS\SerializerBundle\JMSSerializerBundle($this),
new FOS\RestBundle\FOSRestBundle(),
This seems to have sorted it for me.
i followed this doc to install SonataMediaBundle but i got this error:
PHP Fatal error: Class 'Application\Sonata\MediaBundle\ApplicationSonataMediaBundle' not found in /var/www/znata.com/app/AppKernel.php on line 47
After using the sonata command t generate the app:
php app/console sonata:easy-extends:generate SonataMediaBundle
new directory was generated under:
apps/Application/Sonata/MediaBundle
everything was done but when i registred the generated application in my AppKernel.php i got that error.
public function registerbundles()
{
return array(
...
new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),
...
);
}
Have you any idea how to fix this issue ?
By default project root directory is not in the autoload path, only "src" dir.
You can use
php app/console sonata:easy-extends:generate --dest=src SonataMediaBundle
to generate bundle in the src or simple copy it to the src.
After debug this problem, i found that the namspace Application is not registred.
In SF2.0, the documentation said that we should register this namespace like:
<?php
$loader->registerNamespaces(array(
...
'Application' => __DIR__,
'Imagine' => __DIR__.'/../vendor/imagine/lib',
'Gaufrette' => __DIR__.'/../vendor/gaufrette/src',
'Buzz' => __DIR__.'/../vendor/buzz/lib',
...
));
but in SF2.1 they did talked about this.
So i registred the namespace Application in autoload.php and it works fine.
so, the autoload.php look like this:
<?php
// file: app/autoload.php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
//custom for Application
$loader->add("Application", __DIR__);
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
With this new config everything is fine.But in SF2.0, they talked also about "Imagine", "Guffrette" and "Buzz" namespaces. So perhapes, when using them, we should register them also like Application namespace.
I hope that this helps you.
Using composer I did this in composer.json:
"autoload": {
"psr-0": {
"": "src/",
"Application": "app/"
}
},
I added the mapping "Application": "app/".
And then run
composer update
This generated extra autoloading needed.
inside your composer.json file, have:
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle",
"Application\\": "src/Application"
},
}
do a simple:
composer dump-autoload
to re-generate the autoload files.
new Application\Sonata\MediaBundle\MediaBundle(),
or
new Application\Sonata\MediaBundle\SonataMediaBundle(),
As skonsoft mentioned, you need to load the namespaces in autoload.php. I had the same issue with FOQ.Elastica and resolved it by adding the following.
$loader->add('FOQ', __DIR__.'/../vendor/bundles');
You can also use your app namespace prefix so the package falls under your namespace
bin/console sonata:easy-extends:generate --dest=src SonataMediaBundle --namespace_prefix=App