I am trying to set up FOSElasticaBundle.
Composer json entry:
"friendsofsymfony/elastica-bundle": "^3.2"
I was following official docs tutorial, but this line doesn't work:
$finder = $this->container->get('fos_elastica.finder.app.user');
error i get:
You have requested a non-existent service "fos_elastica.index.app.user".
Do you have any idea why ?
Things i checked:
AppKernel.php contains 'new FOS\ElasticaBundle\FOSElasticaBundle(),'
Profiler under 'Configuration' tab does not show 'FOSElastica' as enabled :(
config.yml:
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
app:
types:
user:
mappings:
email: ~
persistence:
# the driver can be orm, mongodb, phpcr or propel
# listener and finder are not supported by
# propel and should be removed
driver: orm
model: AppBundle\Entity\User
provider: ~
listener: ~
finder: ~
Thanks in advance for any insights, guys :)
Turns out bundle didn't install properly.
"minimum-stability": "dev",
in composer.json on fresh installation worked
Related
I installed ElasticSearch 6 with their Docker image and everything work well.
Then I installed and configured FOSElastica like the doc said.
This is the following config of fos_elastica
fos_elastica:
clients:
default: { host: '%env(ELASTICSEARCH_HOST)%', port: '%env(ELASTICSEARCH_PORT)%' }
serializer:
serializer: jms_serializer
indexes:
app:
client: default
types:
user:
serializer:
groups: [elastica]
persistence:
driver: orm
model: AppBundle\Entity\User
provider: ~
listener: ~
finder: ~
And the model of my User entity to give the elastica serializer group to some field
AppBundle\Entity\User:
exclusion_policy: ALL
properties:
firstname:
expose: true
groups: [elastica, list, details]
lastname:
expose: true
groups: [elastica, list, details]
locale:
expose: true
groups: [elastica, details]
The serializer is working well for my API and is well configurated
jms_serializer:
metadata:
auto_detection: true
directories:
AppBundle:
namespace_prefix: 'AppBundle'
path: '%kernel.project_dir%/config/serializer'
When I'm trying to populate ElasticSearch I get, I think a bad serialization error
In Http.php line 181:
[Elastica\Exception\ResponseException]
Malformed action/metadata line [3], expected START_OBJECT but found [VALUE_STRING]
I tried to set field typing using properties.type config in the fos_elastica configuration without success.
I tried with another entity and I get the same error.
I have already work with FOSElasticaBundle ~1year ago on the same project and population was working...
I didn't success to find where is the problem, if there is a JMSSerializer/FOSElastica bug or a misconfig
Did I miss something in the configuration ? Do you already had this issue ?
I had a similar problem. Here are the original elastic configs (which gave this error).
fos_elastica:
clients:
default: { host: '%env(ELASTICSEARCH_HOST)%', port: '%env(ELASTICSEARCH_PORT)%' }
serializer:
serializer: jms_serializer
indexes:
app:
finder: ~
types:
goods:
properties:
name: { type: text }
brand: { type: text }
cost: { type: float }
category:
type: "object"
properties:
id: ~
name: ~
goodsDescriptions:
type: "object"
properties:
id: ~
name: ~
description: ~
persistence:
driver: orm
model: App\Entity\Goods\Goods
provider: ~
finder: ~
repository: App\SearchRepository\GoodsRepository
However, I climbed inside the vendor foselastic for a long time and noticed that the data for adding it took based on jms_serializer, which was obvious, but at that time I thought otherwise. By removing this serialization and it was worked.
We have different settings, but maybe it will give you an idea.
To avoid this error just remove the
JSON_PRETTY_PRINT
from your JMS/Symfony Serializer config.
In development everything works. When I switch to production and try to search I simply get 500 error. There are no errors written in logs so I dont understand what can be wrong?
When going to the http://localhost:9200/_plugin/head/. I see that the products are saved in index app_dev.
However there is not index related to app. Why is that? Why is it not creating indexes in prod?
config.yml:
fos_elastica:
default_manager: orm
clients:
default: { host: localhost, port: 9200 }
indexes:
app:
index_name: app_%kernel.environment%
types:
product:
mappings:
id:
type: integer
adminTitle:
type: string
base:
type: double
created_at:
type: date
persistence:
# the driver can be orm, mongodb, phpcr or propel
# listener and finder are not supported by
# propel and should be removed
driver: orm
model: Mp\ShopBundle\Entity\Product
provider: ~
listener:
immediate: ~
finder: ~
repository: Mp\ShopBundle\Repository\ProductRepository
elastica_to_model_transformer:
query_builder_method: findProductsBySearch
ignore_missing: true
I am having difficulty configuring the Doctrine Extension Taggable provided here:
https://github.com/FabienPennequin/DoctrineExtensions-Taggable
My project is using Symfony 2 Fullstack and my configuration is using yaml while my doctrine entities are using annotation. I installed DoctrineExtensions using composer. Adding "fpn/doctrine-extensions-taggable": "dev-master" to the require section on composer.json and then running composer update. This installed without issue.
I then become lost at this section: https://github.com/FabienPennequin/DoctrineExtensions-Taggable#setup-doctrine
I understand that the metadata is a Doctrine Entity however as previously mentioned I am using yaml for my symfony configuration as well as entity managers. Here is the excerpt from my config.yml file:
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
default_entity_manager: main
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
main:
connection: default
mappings:
VendorMainBundle:
prefix: Vendor\MainBundle\Entity
taggable:
connection: default
mappings:
taggable:
type: xml
prefix: DoctrineExtensions\Taggable\Entity
dir: %kernel.root_dir%/../vendor/fpn/doctrine-extensions-taggable/metadata
However, when I run php app/console doctrine:mapping:info --em=taggable I get the error:
[Exception]
You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors.
Should the above command show the mappings described in the xml files?
Thereby allowing me to update the schema in the database?
I used this documenation as reference for the config.yml file: http://symfony.com/doc/current/reference/configuration/doctrine.html#mapping-configuration
I also added this under the config.yml in order to setup the TagListener. Is this correct?
services:
taggable:
class: DoctrineExtensions\Taggable\TagListener
EDIT [#Grimv01k]:
The TagListener requires an argument passed that is an instance of the TagManager Object. I created another service to handle that as follows and passed it to the TagListener:
tag.manager:
class: DoctrineExtensions\Taggable\TagManager
tags:
- { name: doctrine.event_subscriber, connection: default }
arguments:
entity.manager: #doctrine.orm.entity_manager
taggable:
class: DoctrineExtensions\Taggable\TagListener
arguments:
manager: #tag.manager
The TagManager requires an argument of the entityManager however by doing so results in error:
[Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException]
Circular reference detected for service "doctrine.dbal.default_connection", path: "doctrine.dbal.default_connection".
Across the web it's recommended to resolve this error by passing #service_container and in the constructor of the object pull out the entity_manager, however being a vendor I'd prefer not to modify their code. Is there another way?
Just guess: maybe that happens becuse you haven't got tags applied in service, and Doctrine doesn't use this in your complier pass. Try to do it like this:
services:
taggable:
class: DoctrineExtensions\Taggable\TagListener
tags:
- { name: doctrine.event_subscriber, connection: default }
I am trying to configure KnpGaufretteBundle with the help of KnpLabs
But at the point of configuring Filesystems in config.yaml I got this error
ContextErrorException: Notice: Undefined variable: adapters in
C:\xampp\htdocs\symfony2\src\Knp\Bundle\GaufretteBundle\
DependencyInjection\KnpGaufretteExtension.php
line 50
I have tried a lot to solved it.
Can any know how to remove this error or how to configure KnpGaufretteBundle Bundle in symfony 2.3.5 ?
Any help would be appreciated.
You most likely forgot to add your adapters to the bundle configuration. That's why you end up with the exception when the extension tries to setup the filesystems here ($adapters is unedefined).
Please follow the documentation Configuring the Adapters
Thanks for reply,
in my config.yml i write below code
knp_gaufrette:
adapters:
foo:
local:
directory: /path/to/my/filesystem
app/config/config.yml
knp_gaufrette:
adapters:
# ...
filesystems:
bar:
adapter: foo
alias: foo_filesystem
Thanks you all, i have made following changes and its start working...
knp_gaufrette:
adapters:
foo:
local:
directory: /path/to/my/filesystem
create: true
app/config/config.yml
knp_gaufrette:
adapters:
foo:
safe_local:
directory: /path/to/my/filesystem
create: true
I've got the error [Solution at the end of the question]
Fatal error: Class 'symblog\Blogger\BlogBundle\SymblogBundle' not found in
/var/www/Symfony/app/AppKernel.php on line 20
I founded the question How to install or integrate bundles in Symfony2, but the solutions given didn't help me, because I already did what is suggested there. I'm following the tutorial symblog.co.uk except that I created at
app/config/routing.yml
a
*.php resource
Thanks in advance!
I have to add that while registering the bundle by console I've got the error
The command was not able to configure everything automatically.
You must do the following changes manually.
And the instructions:
- Edit the app/autoload.php file and register the bundle
namespace at the top of the registerNamespaces() call:
'symblog\Blogger\BlogBundle' => '/var/www/Symfony/blog',
which I followed.
AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
//..
new symblog\Blogger\BlogBundle\SymblogBundle(),
);
/app/config/routing.yml
SymblogBundle:
resource: "#SymblogBundle/Resources/config/routing.php"
prefix: /
As requested: /app/config/config.yml
imports:
- { resource: parameters.ini }
- { resource: security.yml }
framework:
#esi: ~
#translator: { fallback: %locale% }
secret: %secret%
charset: UTF-8
router: { resource: "%kernel.root_dir%/config/routing.yml" }
form: true
csrf_protection: true
validation: { enable_annotations: true }
templating: { engines: ['twig'] } #assets_version: SomeVersionScheme
session:
default_locale: %locale%
auto_start: true
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
# java: /usr/bin/java
filters:
cssrewrite: ~
# closure:
# jar: %kernel.root_dir%/java/compiler.jar
# yui_css:
# jar: %kernel.root_dir%/java/yuicompressor-2.4.2.jar
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
jms_security_extra:
secure_controllers: true
secure_all_services: false
[Edit] The solution was very easy after the answer from #Clamidity that the bundles usually are located at src/Blogger/SymBlogBundle/BloggerSymBlogBundle.php
While the configuration using the console it saked about the location of the bundle and the default was /../src but I changed to /../blog. And of course it won't work, Symfony was looking into the wrong location. What I did was to move the folders inside /blog to /src and everything went fine.
There are a few things that it could be. I'll just cover anything I can think of.
Generally bundles are placed in the src folder. So the path to your bundle should look like this.
src/Blogger/SymBlogBundle/BloggerSymBlogBundle.php
(Notice that the bundle name follows the file name convention)
Inside of the BloggerSymBlogBundle.php make sure you have something similar to the following:
<?php
namespace Blogger\SymBlogBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class BloggerSymBlogBundle extends Bundle
{
}
(Notice that the same name convention is also followed here)
In your autoload.php the namespace that should be registered is the "Blogger" part of the name/path to your bundle. This is because the bundle itself resides in the Blogger folder:
'Blogger' => __DIR__.'/../src',
(Notice that the folder listed is the parent of the Blogger folder)
Now in the AppKernel.php register the bundle according the namespace your set up and registered:
new Blogger\SymBlogBundle\BloggerSymBlogBundle(),
*Note - Your resources and references to this bundle with the above configuration would be
BloggerSymBlogBundle
so your php routing would be called by using:
#BloggerSymBlogBundle/Resources/config/routing.php
There are different solution.
Clear the app/cache/(prod|dev) folder. When you have edited the Appkernel and autoload.
Fatal error: Class 'symblog\Blogger\BlogBundle\SymblogBundle' not found in
/var/www/Symfony/app/AppKernel.php on line 20
Here are now different Problems:
Look to the SymblogBundle.php in the Bundle Folder and look which namespace they use. Perhaps its really an uppercase ("S") like #kuba said.
The Class file is not in the folder or you have no rights to the folder that the interpreter can load the file.
I think your autoload.php is not correct.
'Avalanche' => __DIR__.'/../vendor/bundles',
This is the common way to register an Namespace. In your case it have to be
'Symlog' => '/var/www/Symfony/blog',
Here are the instructions from the "BloggerBundle" I hope its the correct one
There you can see the your autoload its not correct the Namespace is "Blogger".