Standalone doctrine annotation routing - cannot load resource - symfony

I have a routes.yml file
controllers:
resource: ../src/Controller/
type: annotation
I am trying to load it
$loader = require __DIR__.'/../vendor/autoload.php';
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
$locator = new FileLocator([__DIR__.'/../config']);
$loader = new YamlFileLoader($locator);
$routeCollection = new RouteCollection();
$importedRoutes = $loader->load("routes.yml");
And I get
Cannot load resource "../src/Controller/". Make sure annotations are installed and enabled.
I have tried variations, with and without quotes, backslashes, forward slashes...
"../src/Controller/"
"../src/Controller/API.php"
I have both doctrine/annotations and sensio/framework-extra-bundle installed
A similar issue came up in the Symfony Github issues, but I seem to have done what the solution is, according to Fabien Potencier.
To clarify, I am not using the complete Symfony package, but trying to use individual components to build the routing. Any ideas why I am getting this error message?

Related

Depraction warning loading file assets from src is deprecated

I have stuff like #import '../assets/scss/WebsiteBundle/font.scss'; in scss/WebsiteBundle/default.scss, however, since Symfony 4.4 I get the following depracitation warning.
Loading the file "../assets/../_photo.scss" from the global resource directory ".../src" is deprecated since Symfony 4.4 and will be removed in 5.0.
I can't seem to find anything in the documentation about this. Can someone help me?
In the routes.yaml file, make sure that you have all your routes with the directive type, this fixed this bug for me.
Example as it follows:
api:
prefix: /api
resource: '../src/Controller/Api'
type: annotation
I fixed this by using
$configDirectories = [__DIR__ . '/../../templates'];
$fileLocator = new FileLocator($configDirectories);
$fileName = $fileLocator->locate($resource, null, true);

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.

Symfony2 - integration of ckeditor and sonata media bundle

I am trying to integarte IvoryCKEditor with sonata media bundle. Perpose is to allow image uploads in ckeditor. I tried it using a CoopTilleulsCKEditorSonataMediaBundle but i keep getting an error:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "admin_sonata_media_media_ckeditor_browser" as such route does not exist.") in "IvoryCKEditorBundle:Form:ckeditor_widget.html.twig".
Thanks :)
You should check your routes with the command:
$ php app/console debug:router | grep ckeditor
Then you have to replace admin_sonata_media_media_ckeditor_browser and admin_sonata_media_media_ckeditor_upload by routes founded with this command, in the config of ivory_ck_editor (maybe in your config.yml or your ivory_ckeditor.yml file)
If you don't have route for ckeditor, I think you should check if you install correctly the bundle.
1) install SonataFormatterBundle 2) add the bundle and its dependencies in AppKernel 3) config files 4) CLEAR CACHE 5) roll
Reason of the issue
This problem arises when trying to integrate CKEditor through the
SonataFormatterBundle without using the SonataAdminBundle.
In fact, the integration proposed by the SonataFormatterBundle is meant to only work for the SonataAdminBundle, and no easy integration for a custom admin bundle is currently available.
Note that this dependency is not specified in the documentation at the moment.
How to solve the problem
Simply install the SonataAdminBundle following this installation process. You do need to configure the bundle entirely as specified in the documentation. To add the routes that were missing, such as admin_sonata_media_media_ckeditor_browser, simply add the following to your config/routes.yml:
# This is your custom admin bundle
admin:
resource: "#AdminBundle/Controller/"
type: annotation
prefix: /admin/
# Import SonataAdminBundle routes
admin_area:
resource: "#SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin/sonata # put whatever prefix here
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
Just to add something.
If you are SURE that you have installed, all dependencies, and set all configs correctly, and still getting this error, then the cause may be that you have defined your 'sonata_media' prefix in routing.yml differently.
You can check all urls in your project in:
app/cache/dev/appDevUrlGenerator.php
In there you will find ALL routes in a variable $declaredRoutes
Afterwards simply put correct route name for browsing.
It will not work without SonataMediaBundle - you will need to install it with SonataFormatterBundle
Sonata become too complicated as for me, so I just use IvoryCKEditorBundle directly

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

Unable to import the routing in symfony

I am using the Jobeet tutorial.
I have configured the routing in app/confing file as follow:
EnsJobeetBundle:
resource: "#EnsJobeetBundle/Resources/config/routing.yml"
prefix: /
In EnsJobeetBundle routing it is defined as below:
EnsJobeetBundle_job:
resource: "#EnsJobeetBundle/Resources/config/routing/job.yml"
prefix: /job
When I am using the URL http://localhost/Symfony/web/app_dev.php/job/ I get the following error:
Cannot import resource "#EnsJobeetBundle/Resources/config/routing/job.yml"
from "C:\wamp\www\Symfony\src\Ens\JobeetBundle/Resources/config/routing.yml".
Make sure the "EnsJobeetBundle/Resources/config/routing/job.yml" bundle
is correctly registered and loaded in the application kernel class.
I have also registerd in appkernel file also as follow:
new Ens\JobeetBundle\EnsJobeetBundle(),
What may cause these errors?
In my case, when trying a production url I was getting this same error.
In app/AppKernel.php there is a condition that only considers 'dev' and 'test' environment:
if (in_array($this->getEnvironment(), array('dev', 'test')))
if your bundle should also be enabled in prod environment you should modify the condition:
if (in_array($this->getEnvironment(), array('prod', 'dev', 'test')))
This solved the error for me.

Resources