Generate admin Sonata with command line in Symfony 4 - symfony

I'm starting to use Sonata with Symfony 4.
I try to generate an admin with the command line "make:sonata:admin" and i've an error at the end of the process like this:
2018-10-11T15:55:23+00:00 [error] Error thrown while running command "make:sonata:admin". Message: "There are no model managers registered."
In AdminMaker.php line 286:
There are no model managers registered.
So I try wit hthe other command line "sonata:admin:generate" and I have an other error like this :
Welcome to the AdminBundle object ACL generator
This command helps you to generate ACL entities for the objects handled by the AdminBundle.
If the step option is used, you will be asked if you want to generate the object ACL entities for each Admin.
You must use the shortcut notation like AcmeDemoBundle:User if you want to set an object owner.
Admin class is using a manager type that has no manipulator implemented : ignoring
Admin class is using a manager type that has no manipulator implemented : ignoring
Admin class is using a manager type that has no manipulator implemented : ignoring
My implementation code is like this :
src
Entity
Clients
Vehicules
Can you help me please ?
Thanks a lot for your answer

Try to config the service, so you can give the model manager that you use.
services:
sonata.admin.maker:
class: Sonata\AdminBundle\Maker\AdminMaker
arguments: ['%kernel.project_dir%', ['#sonata.admin.manager.orm']]
tags:
- { name: maker.command }

You need to install Doctrine ORM Admin Bundle first
composer require sonata-project/doctrine-orm-admin-bundle

Related

bundle's service (autowire) not available in controller's method

I'd like to use https://github.com/tedious/TedivmStashBundle bundle in my symfony 4 project. Added by composer, configured in /config/stash.yaml file and according to the profiler bar, it's working basically.
Now, I want to use to caching values in my controller. I've try to add the service stash by its name to the method's parameter, using the same name as the example says:
$pool = $this->container->get('stash');
but the framework did not find the service. It can't be added like the example explained neither.
How can I use this bundle as a service (autowired) in my symfony 4 app?
UPDATE
services.yaml:
stash.default_cache:
class: Tedivm\StashBundle\Service\CacheService
public: true
arguments:
$name: 'stash'
Tedivm\StashBundle\Service\CacheService: '#stash.default_cache'
Controller:
public function something(Request $request, CacheService $service, ...
It's looks like working now :)
Thanx for the suggestion (and the correct solution later) to #Cerad
Here is an example of how to approach this sort of problem when dealing with bundles that are not quite ready for autowire.
Start by installing a test project:
symfony new --full stash --version=lts
composer require tedivm/stash-bundle
Note that the bundle does not directly support Symfony 5 hence the lts. Note also that the bundles does not support Flex so you have to add your own config/packages/stash.yaml file per the bundle's readme file.
# config/packages/stash.yaml
stash:
drivers: [ FileSystem ]
FileSystem: ~
At this point we can determine which service we need to inject:
bin/console debug:container stash
Information for Service "stash.default_cache"
=============================================
Class CacheService
---------------- -----------------------------------------
Option Value
---------------- -----------------------------------------
Service ID stash.default_cache
Class Tedivm\StashBundle\Service\CacheService
Most of the time you would like to use an interface for injection but a peek at the source code reveals that the bundle does not use interfaces. As a side note, calling a third party service 'stash' is not a good idea. It really should have been 'tedivm.stash' but I digress.
We can now create an alias and then typehint against it:
# config/services.yaml
Tedivm\StashBundle\Service\CacheService : '#stash' # alias for typehinting
# Controller class
public function index(CacheService $cacheService)
{
return new Response('Cache ' . get_class($cacheService));
}
And that should do it.

SYMFONY3 in prod look for TWIG template in wrong folder instead of custom bundle indicated in routing.yml and AppKernel.php

I am implementing a SYMFONY 3 project in production mode for the first time.
I follow OceanDigital tutorial and the standard doc.
I went thru a bunch of issues linked to user writing rights that I've solved, and I do get now a SYMFONY ERROR page (one step closer to victory) with this message:
Unable to find template "MyBundle:std_page:home.html.twig" (looked
into: /[folder to symf project]/app/Resources/views,
/[folder to symf project]/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form,
/[folder to symf project]/vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views).
If I look in my [my symf project]\app\config\routing.yml, I have:
my_bundle:
resource: "#MyBundle/Resources/config/routing.yml"
options:
expose: true
In [my symf project]\app\AppKernel.php, in the registerBundles() function, I have:
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
....
new MyBundle\MyBundle(),
.....
]
}
}
And the file regarding the template that should be fetched [my symf project]\src\MyBundle\Ressources\views/std_page/home.html.twig exists.
What did I not set up right, in production mode, to have it looking for the TWIG template in the folder [my symf project]\src\MyBundle\Ressources\views/?
After some search it happens to be a mistake similar to the one described in that SO thread.
In my controller I had:
return $this->render('MyBundle:Std_page:home.html.twig',$parameters);
Instead of:
return $this->render('MyBundle:std_page:home.html.twig',$parameters);
The development was made on a WINDOWS 10 OS, and it is set up in production on a UBUNTU 16.04. It seems that UBUNTU is stricter than WINDOWS regarding the letter case.

EasyAdminBundle ReflectionException at create Backend section of install

Having an issue with the final stage of the setup of Easy Admin in a fresh Symfony 3 install,
at the "Your First Backend" : Creating the backend for those entities just require you to add the following configuration in the app/config/config.yml file:
# app/config/config.yml
easy_admin:
entities:
- AppBundle\Entity\Product
- AppBundle\Entity\Category
- AppBundle\Entity\User
When I do this I get error :
[ReflectionException] Class
AppBundle\Entity\Product does not exist
All the previous commands for setup installed without error, including installing the assets.
In documentation of EasyAdminBundle You have
Let's suppose that your Symfony application defines three Doctrine ORM entities called Product, Category and User.
In entities section you need to list already existing in your app Entities. If you don't have any - create it.
Docs: https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/getting-started/2-first-backend.md

Symfony2: overriding Sensio FrameworkExtraBundle template guesser

I am trying to override the standard template guesser ( located in Sensio\Bundle\FrameworkExtraBundle\Templating; ) becouse I want to use annotations to set the view but need to change the logic of how the actual view file is chosen.
I have seen this: https://github.com/elnur/ElnurTemplateGuesserBundle
but I was wondering if there is a way to just override the service in configuration.
I tried setting:
services:
sensio_framework_extra.view.guesser:
class: myCompany\myBundle\Templating\TemplateGuesser
but I get:
ContextErrorException: Catchable Fatal Error:
Argument 1 passed to Sensio\Bundle\FrameworkExtraBundle\Templating\TemplateGuesser::__construct()
must implement interface Symfony\Component\HttpKernel\KernelInterface, none given
Am I supposed to set an argument in the service config setting? But how do I reference the HttpKernel?
Or am I missing something?
TIA.
You can inject the kernel the same way the as the original TemplateGuesser. The name of the Kernel service is just simply kernel.
services:
sensio_framework_extra.view.guesser:
class: myCompany\myBundle\Templating\TemplateGuesser
arguments: [ "#kernel" ]
To see a full list of services in the container, run
$ php app/console container:debug
Of which you'll see the kernel listed as one of them.

Symfony2 CRUD routing Failed

After executing the following command for CRUD generation:
php app/console generate:doctrine:crud --entity=AcmeDemoBundle:Users --format=yml
i get error for automatic routing update by CRUD for each entity.
Confirm automatic update of the Routing [yes]? yes
Importing the CRUD routes: FAILED
The command was not able to configure everything automatically.
You must do the following changes manually.
- Import the bundle's routing resource in the bundle routing file
(C:\wamp\www\symfony\src\Acme\DemoBundle/Resources/config/routing.yml).
AcmeDemoBundle_categories:
resource: "#AcmeDemoBundle/Resources/config/routing/categories.yml"
prefix: /categories
I also tried creating a new bundle but still gets same error. So everytime i add the above code in routing file /src/Acme/DemoBundle/Resources/config/routing.yml
Can someone please suggest what i am missing?
I get the same thing, not sure how to get the generation to work right but it wants you to add that code to your main routing.yml file so it can link the generated routes:
AcmeDemoBundle_categories:
resource: "#AcmeDemoBundle/Resources/config/routing/categories.yml"
prefix: /categories

Resources