Symfony 2 production app unable to find any Twig template - php

I made Symfony 2 app what is working well on production and dev mode in my localhost server, but when i pushed it live to my ftp there was a problem. I checked log's and it's looks like Twig has problems with finding templates.
There is log from my server:
[2015-05-18 11:10:21] request.INFO: Matched route "homepage" (parameters: "_controller": "AppBundle\Controller\DefaultController::indexAction", "_route": "homepage") [] []
[2015-05-18 11:10:21] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2015-05-18 11:10:21] request.CRITICAL: Uncaught PHP Exception InvalidArgumentException: "Unable to find template "AppBundle:Home:index.html.twig"." at /vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php line 128 {"exception":"[object] (InvalidArgumentException(code: 0): Unable to find template \"AppBundle:Home:index.html.twig\". at /vendor/symfony/symfony/src/Symfony/Bridge/Twig/TwigEngine.php:128, Twig_Error_Loader(code: 0): Unable to find template \"AppBundle:Home:index.html.twig\". at /vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php:91, InvalidArgumentException(code: 0): Unable to find template \"AppBundle:Home:index.html.twig\" : \"Unable to find file \"#AppBundle/Resources/views/Home/index.html.twig\".\". at /vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php:81, InvalidArgumentException(code: 0): Unable to find file \"#AppBundle/Resources/views/Home/index.html.twig\". at /app/bootstrap.php.cache:2456)"} []
[2015-05-18 11:10:21] security.DEBUG: Write SecurityContext in the session [] []
Have anyone idea what's the problem?
#edit I also put my config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#AppBundle/Resources/Config/services.yml" }
framework:
#esi: ~
#translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.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
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
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%"
spool: { type: memory }
#for user
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: AppBundle\Entity\User
registration:
form:
type: new_user_registration
#vich file uploader
vich_uploader:
db_driver: orm
mappings:
download_file:
uri_prefix: /files/download
upload_destination: %kernel.root_dir%/../web/files/download
offer_file:
uri_prefix: /files/offer
upload_destination: %kernel.root_dir%/../web/files/offer
inject_on_load: false
delete_on_update: false
delete_on_remove: true
Controller:
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
/**
* #Route("/", name="homepage")
*/
public function indexAction()
{
return $this->render('AppBundle:Home:index.html.twig');
}
}
#edit2
I don't know it does matter but i use for my project this template https://github.com/juliomatcom/charisma-symfony-php

Ok i found solution. When i copied files from this repository https://github.com/juliomatcom/charisma-symfony-php I have not noticed the 'Views' folder starts from uppercase. When i change it to 'views' everything works fine.
Thanks for everyone who tried help :)!

Related

No route found for all my routes even though they show up in debug:router

Background:
I am trying to learn Symfony3 and was playing around with Internationalization.
Issue:
I broke something and I can't get my routes to work again. The only route that is working is localhost:8000/ (homepage)
What I have at the moment:
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#CarBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
translator: { fallbacks: [en] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form_themes:
- 'bootstrap_3_layout.html.twig'
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/../var/data/data.sqlite"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
routing.yml
app:
resource: "#AppBundle/Controller/"
type: annotation
car:
resource: "#CarBundle/Controller/"
type: annotation
Example controller (for login)
<?php
/**
* Handles login operations
*/
namespace AppBundle\Controller;
use AppBundle\Entity\User;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use function dump;
class SecurityController extends Controller
{
/**
* #Route("/login", name="login")
*/
public function loginAction(Request $request)
{
// here we are getting a service from the container
$authenticationUtils = $this->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', array(
'last_username' => $lastUsername,
'error' => $error,
));
}
}
All my routes
Just to be clear: I have tried bin/console cache:clear and many different configuration options... to no avail...
EDIT 1: The profiler has the following message:
Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /login/" (from "http://localhost:8000/register")" at C:\xampp\htdocs\php\frameworks\symfony\autotrader\var\cache\dev\classes.php line 3487
EDIT 2: New error after removing use function dump;
Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /login/" (from "http://localhost:8000/")" at C:\xampp\htdocs\php\frameworks\symfony\autotrader\var\cache\dev\classes.php line 3487
You have not set /login/ route but only /login route - without last slash in your routes.

Redirecting with a route in Symfony2.8

I'm trying to redirect with a route and I', following the official doc Symfony doc
But I've edited the config.yml file with the route field
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#UserBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
translator: { fallbacks: [en] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#default_locale: "%locale%"
default_locale: es
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
root:
path: /crearUser
defaults:
_controller: UserBundle:Default:create
route: crear
permanent: true
But I get this error
InvalidArgumentException in YamlFileLoader.php line 399: There is no extension able to load the configuration for "root" (in /home/user/pruebasym/app/config/config.yml). Looked for namespace "root", found "framework", "security", "twig", "monolog", "swiftmailer", "doctrine", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution"
It looks like a missed somenthing but I haven't seen anything diferrent a the official doc
The identation level is not correct, If you want to set it in your config.yml, you must follow this indentation level :
framework:
router:
root:
path: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /app
permanent: true
Or simpler, in your routing.yml (like the symfony doc suggests) :
root:
path: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /app
permanent: true

Symfony internationalization

I am having a strange problem with translation in Symfony 2.
This is my config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
framework:
#esi: ~
translator: { fallbacks: ['%locale%'] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
mapping_types:
enum: string
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
fos_user:
db_driver: orm
firewall_name: main
user_class: AppBundle\Entity\User
profile:
form:
type: app_user_profile
parameters.yml
...
locale: ru
And, of course, I have messages.en.yml and messages.ru.yml.
Even when locale is set to 'ru' it displays English text, and $request->getLocale() is always returning 'en'.
What could be the problem and where is it overset to 'en' if not in configs?
The locale parameter in the config.yml file is just a fallback in case a translation for the requested language is not available.
Calling $request->getLocale() will return the language configuration of the browser from which the HTTP-Request was sent.
If you want the translation to be forced into another language take a look at this answer: https://stackoverflow.com/a/14331838/1173391
You need to create a twig extension that allows you to replace ru with en in your path route (and vice versa) :
{# yourProject/app_dev.php/ru #}
Look at this tutorial
http://blog.viison.com/post/15619033835/symfony2-twig-extension-switch-locale-current-route
put in your routing.yml a prefix with the locale like this:
routing.yml
app:
resource: "#AppBundle/Controller/"
type: annotation
prefix: /{_locale}
requirements:
_locale: "%app.locales%"
config.yml
parameters:
locale: en
app.locales: en|ru
Did you add:
{% trans_default_domain "message" %}
on top of your twig template file where the translation keys exist and did you clear cache?

How to use global variable in symfony twig file?

I have done setting in app/config/config.yml
twig:
globals:
mandatory_note: %mandatory_note%
parameter also set in config.yml file
parameters:
mandatory_note: "Note: * marked fields are mandatory"
And in twig file I have accessed the variable
{{ mandatory_note }}
but still gets error. ie. mandatory_note variable doesnot exists.
This is my config.yml file
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
cookie_lifetime: 0
gc_maxlifetime: 36000
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: []
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
unix_socket: "/opt/lampp/var/mysql/mysql.sock"
charset: UTF8
mapping_types:
enum: integer
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
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%"
spool: { type: memory }
encryption: "%mailer_encryption%"
port: "%mailer_port%"
sender_address: "%mailer_sender%"
parameters:
max_contents_per_page: 20
max_pages_per_page: 10
mandatory_note: "Note: * marked fields are mandatory"
twig:
globals:
mandatory_note: %mandatory_note%
You need to put it under Twig. Like that:
twig:
globals:
mandatory_note: %mandatory_note%
Also make sure that mandatory_note is defined in parameters.yml file. To test if global works just use "testString" instead of %mandatory_note%
What if you put them together, like this?
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
globals:
mandatory_note: "%mandatory_note%"
I got solution, I added below code in parameters.yml file:
parameters:
mandatory_note: "Note: * marked fields are mandatory"
twig:
globals:
mandatory_note: "%mandatory_note%"
and it's working finally.

Dashboard and login page complete blank sonata admin bundle

About 3 days ago I updated my composer to install another bundle.
Since then my /admin/login and /admin/dashboard routes are complete blank (a blank page html)
No errors, no warnings, nothing.
If I remove Roles I can access entites admin page directly (like /admin/product/edit...). But login and dashboard still blank.
I reinstalled bundles any times and I really don't know what I can do now.
Here is my files:
#app/config/config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: #VisaoAdminBundle/Resources/config/admin.yml }
framework:
#esi: ~
translator: { fallback: pt_BR }
secret: %secret%
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: %kernel.debug%
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: pt_BR
trusted_proxies: ~
session: ~
fragments: ~
# fos-user
fos_user:
db_driver: orm
firewall_name: main
user_class: Application\Sonata\UserBundle\Entity\User
group:
group_class: Application\Sonata\UserBundle\Entity\Group
group_manager: sonata.user.orm.group_manager
service:
user_manager: sonata.user.orm.user_manager
sonata_user:
manager_type: orm # can be orm or mongodb
# sonata-admin
sonata_admin:
title: Visão Brindes e Impressos
title_logo: bundles/visaomain/images/logo_visao_brindes_admin.png
# sonata-block
sonata_block:
default_contexts: [cms]
blocks:
# Enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
sonata.block.service.text:
sonata.block.service.action:
sonata.block.service.rss:
# Your other blocks
# Twig Configuration
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: %kernel.root_dir%/Resources/java/compiler.jar
#yui_css:
# jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.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
types:
json: Sonata\Doctrine\Types\JsonType
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: %kernel.root_dir%/data/data.db3
# path: %database_path%
orm:
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
Thank you!

Categories