Unable to import the routing in symfony - 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.

Related

Standalone doctrine annotation routing - cannot load resource

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?

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.

Deploying symfony to Heroku, get swiftmailer parameters via configvars

I have deployed my symfony app to Heroku, but I want to configure the swiftmailer component with config_vars provided by Heroku. I already have two of them:
SYMFONY_ENV: prod
CLEARDB_DATABASE_URL: my-connection-string
Now what I would like to do is to decribe swiftmailer credentials in the config_prod.yml:
#config_prod.yml
swiftmailer:
transport: "%env(mail_transport)%"
host: "%env(mail_host)%"
username: "%env(mail_user)%"
password: "%env(mail_password)%"
spool: { type: memory }
I, then, set up the config_vars on Heroku, however when trying to deploy the app I got the following exception.
[Symfony\Component\DependencyInjection\Exception\EnvParameterException]
Incompatible use of dynamic environment variables "mail_transport" found in parameters.
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
Unable to replace alias "swiftmailer.mailer.default.transport.real" with actual definition "%env(mail_transport)%".
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
You have requested a non-existent service "%env(mail_transport)%".
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception
If I hardcode the parameters in the config.yml then deploying to Heroku succeeds.
What am I messing up? Thx in advance.
I do not know much about heroku but i know how to get ENV_VAR inside symfony config ;)
inside app/config where your other configs files reside create a new file called parameters.php
<?php
if(isset($_SERVER['AWS_MAILER_HOST']) ){
$container->setParameter('mailer_transport', #$_SERVER['AWS_MAILER_TRANSPORT']);
$container->setParameter('mailer_host', #$_SERVER['AWS_MAILER_HOST']);
$container->setParameter('mailer_username', #$_SERVER['AWS_MAILER_USERNAME']);
$container->setParameter('mailer_password', #$_SERVER['AWS_MAILER_PASSWORD']);
$container->setParameter('mailer_port', #$_SERVER['AWS_MAILER_PORT']);
$container->setParameter('mailer_encryption', #$_SERVER['AWS_MAILER_ENCRYPTION']);
$container->setParameter('mailer_auth_mode', #$_SERVER['AWS_MAILER_AUTH_MODE']);
}
replace all 'AWS_MAILER_...' with your ENVIRONEMENT_VAR
Inside your app/config/config.yml put
imports:
- { resource: parameters.yml }
- { resource: parameters.php } <------------

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

Symfony2 multiple config and routing files for subdomain routing

We are building a Symfony2 application that will serve different sections using subdomains:
api.tld.com - API system
docs.tld.com - Documentation
assets.tld.com - System for serving images
How we are doing this is creating an app directory for each subdomain, and keeping the standard /app directory in place as the central shared config. There is also a custom bootstrap in the web directory for each app. Subdomains are routed accordingly using .htaccess.
The problem I am having is where multiple config files come in, particularly when they have their own routing imports. In some cases, there can be up to 4 configs.yml files. Take the following URL for example:
http://testing.docs.tld.com
The config setup currently works like this (and it works)
tld.com - Global config located at /app/config/config.yml
testing - Environment config located at /app/config/config_testing.yml. This config also imports config_dev.yml in the same directory.
docs - App config located at /app_docs/config/config.yml
These are all imported in the AppKernal in /app_docs/AppKernal.php:
// Load Global Configuration
// ROUTES INSIDE THIS CONFIG ARE NOT BEING LOADED
$loader->load(__DIR__.'/../app/config/config.yml');
// Load Environment Configuration
// ROUTES INSIDE THIS CONFIG ARE NOT BEING LOADED
$loader->load(__DIR__.'/../app/config/config_' . $this->getEnvironment() . '.yml');
// Load App-centric Configuration
$loader->load(__DIR__.'/config/config.yml');
Now the configs load just fine. But what I'm having trouble with, and not found any definitive documentation on, is when more than one of these configs define framework: router: resources. In the above example configs, these are loaded (attempted to anyway) as follows:
/app/config/config.yml
framework:
secret:%secret%
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: %kernel.debug%
/app/config/config_testing.yml
// No special Routing
/app/config/config_dev.yml
framework:
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" }
/app_docs/config/config.yml
framework:
secret: %secret%
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: %kernel.debug%
All of the configs are loading fine. But what I found is that only the last routing file called above is being included. So I assume the rule is that they are overriden as a rule, rather than extended.
So what I have spent the last couple of days trying to find out is, is it possible to extend the inclusion of routing files within config files in the fashion above? Another option I investigated was to find a way to import routing files in the AppKernal files. I was only able to find this, which doesn't explain exactly at what point this should be used (or where). It doesn't work within the AppKernal where the configs are included, so I assume the Router is not active at that stage.
Anyone have any ideas? I'd be very grateful.
I had the same need so we did like this:
/apps/config
/apps/config/common_config.yml
/apps/config/common_routing.yml
/apps/config/...
/apps/myapp1
/apps/myapp1/myapp1Kernel.php
/apps/myapp1/...
/apps/myapp1/config
/apps/myapp1/config/config.yml
/apps/myapp1/config/routing.yml
/apps/myapp1/config/...
/apps/myapp2
/apps/myapp2/myapp1Kernel.php
/apps/myapp2/...
/apps/myapp2/config
/apps/myapp2/config/config.yml
/apps/myapp2/config/routing.yml
/apps/myapp2/config/...
...
And in each app's yml file, we had:
/apps/myapp1/config/config.yml
imports:
- { resource: "../../config/common_config.yml" }
And then, you have to reproduce the same way in /web
/web/myapp1/app.php
Who will be calling your app
$kernel = new myapp1Kernel('prod', false);
$kernel->loadClassCache();
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

Resources