I'm working with a project symfony version 2.3.6 specifically. The problem is that I make changes in the code but the change is not reflected on the page until the page charge many times. I'm in dev environment. is as if not compile the code every time I load the page. Are not you supposed to be in dev environment should always be compiled? a greeting
Thanks four your answer. I use MAMP and php 5.5.3 and no select cache.
the app_dev is:
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
//$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
i comment the line //$kernel->loadClassCache(); but the problem no solve.
Symfony caches everything by default, especially Twig. And it's tedious, I know.
Looking at the manual (http://symfony.com/doc/current/book/templating.html) it says:
If you add a template in a new location, you may need to clear your
cache (php app/console cache:clear), even if you are in debug mode.
And so, you need to clear the cache. But attention deleting all, because the user sessions are stored in /cache/dev/sessions. That's another strong limitation: Symfony2 requires a writable filesystem.
There is a radical solution, but your app could get really slow, also in dev mode:
twig:
cache: false
In your config.yml
Related
I have a symfony2 project running with nginx and the problem is that when accessing the prod environment, all the links are still with app_dev.php there.
Here are my config files:
app.php
<?php
require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
use Symfony\Component\HttpFoundation\Request;
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$kernel->handle(Request::createFromGlobals())->send();
The links in the twig file are called this way:
Route name: user_login, in twig: user_login_path()
Where could the problem come from? Nginx?
You should always use path('route_name') in order to generate links or actions. It seems that the function(s) you are using (kind of twig extension) is bad coded and server dependent. But it does not comes with Symfony itself.
You have multiple options :
The cleanest : replace every href, action, ... with the path function
A (maybe) faster one : find the custom twig extension and make it work (more likely in src/Acme/MyBundle/Twig/MyExtension.php)
A quick and dirty one : rewrite every app_dev.php urls to app.dev with a .htaccess (not really recommended at all but... well...)
I just downloaded a fresh copy of Symfony 2.4.1 on a Debian 7.3.
The URL /Symfony/web/config.php opens correctly, but when I proceed to Configure, I get:
The requested URL /Symfony/web/app_dev.php/_configurator/ was not found on this server.
If I Bypass configuration and open /Symfony/web/app_dev.php
the page displays, but an error pops up saying:
An error occurred while loading the web debug toolbar (404: Not Found)
Do you want to open the profiler?
If I accept, I get:
The requested URL /Symfony/web/app_dev.php/_profiler/54a8bf was not found on this server.
In other questions (e.g. Symfony 2: 404 Not Found Error when tryes to open /app_dev.php) people suggest to fiddle with the .htaccess file.
I even tried removing it, but it had no effect.
The apache log file shows:
File does not exist: /var/www/Symfony/web/app_dev.php/_wdt/54a8bf, referer: http://wwwtest.di.unipi.it/Symfony/web/app_dev.php
File does not exist: /var/www/Symfony/web/app_dev.php/_profiler/54a8bf
So it looks like routing to any inner URL fails, despite the fact that the correct routing seems to be in place:
> app/console router:debug
[router] Current routes
Name Method Scheme Host Path
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_configurator_home ANY ANY ANY /_configurator/
...
I have changed memory_limit in /etc/php5/fpm/php.ini to 512Mb and debug toolbar started to work.
Found solution for me here
The solution for me was to update my app_dev.php file to resemble the one in the Symfony2 repo
Notice the Debug class being used. This wasn't used in older versions of symfony. I updated this file and the javascript alert appears to be gone.
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
/*
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
*/
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Is the following present in web/app_dev.php? The line below fixed it for me.
$kernel->terminate($request, $response);
Apache directive DirectoryIndex app.php does the tricks for me.
I put it in apache vhost conf with AllowOverride None to prevent override by .htacces.
Hope this help.
I was following the tutorials for symfony, and have hit a road block.
my setup is the current version of xampp (running on windows), so my apache and php are relatively up to date.
following their "quick tour" here:
http://symfony.com/doc/current/quick_tour/the_big_picture.html
everything worked great in the development environment. following the guides a little further however, i started creating my own test bundle via the guide here:
http://symfony.com/doc/current/book/page_creation.html
and can't get it to work properly on the production environment. (it works fine in the dev environment, just like the pre-installed demos did.
i have tried clearing the cache via the php app/console cache:clear --env=prod --no-debug command, however that did not help (and also seems to be the only suggestion that pops up upon searching.
when viewing the routes, i can see that my "/hello/{name}" route is showing up fine on the list of routes.
my app/config/routing.yml has:
acme_hello:
resource: "#AcmeHelloBundle/Resources/config/routing.yml"
prefix: /
as it should, and then my src/Acme/HelloBundle/Resources/config/routing.yml has
hello:
path: /hello/{name}
defaults: { _controller: AcmeHelloBundle:Hello:index }
does anyone have any suggestions as to what the problem might be? (i have also tried converting the out of the box demo to a production route, by copying the route info from the routing_dev.yml file and reassigning the bundle in the appkernel.php file, but that had the same problem)
---edit---
per request, here is my appkernel.php file
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Acme\HelloBundle\AcmeHelloBundle(),
new Acme\DemoBundle\AcmeDemoBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}
---2nd edit---
i found the problem. i thought it was strange that nothing was showing up in the prod log, so i thought maybe something was redirecting me, causing me to miss the app.php file entirely.
it turns out, this was the problem. i emptied the contents of the .htaccess file that was in the web folder (the one that symfony came preconfigured with) and then everything magically started working.
I also had the same problem. I share how I solved it (Strange but it works).
In file web/app.php change:
$kernel = new AppKernel('prod', false);
by
$kernel = new AppKernel('prod', true); // Enable debug mode
Then load the page in the browser (in app environment) and change the file again disabling debug:
$kernel = new AppKernel('prod', false);
Try loading the page in the browser again. It should work properly.
Best regards,
If you are like me, just want to get the sample application from the tutorial to run in Apache, then this may help you.
I ran into the same problem with version 2.5 just now, and finally found the answer here:
http://symfony.com/doc/current/quick_tour/the_big_picture.html
The demo routes in our application are only available in the dev environment.
Therefore, if you try to access the .../app.php/... URL, you'll get a 404 error.
The easiest way to get it to work is to use app_dev.php instead of app.php.
Just edit .htaccess and change all occurrences of app.php to app_dev.php, like this:
Line 6:
DirectoryIndex app_dev.php
Line 41:
RewriteRule .? %{ENV:BASE}/app_dev.php [L]
Did you try to warm up your cache for the prod environment? You can do this by running the following command:
php app/console cache:warmup --env=prod --no-debug
Also you could check your routes by running
php app/console router:debug
If you want to get specific information on a route you can do php app/console router:debug yourRouteName. But maybe thats what you meant with "viewing the routes".
Another hint has to do with Assets.
Usually if you move your app from dev to prod environment you have to run the following commands:
php app/console assets:install web_directory
php app/console assetic:dump web_directory
Assetic:dump physically genereates your assets, like css stylesheets or javascript files. Something to read about this in detail is here
Perhaps you could edit your post and post your AppKernel.php? Maybe the bundle isn't activated there?
i found the problem. i thought it was strange that nothing was showing up in the prod log, so i thought maybe something was redirecting me, causing me to miss the app.php file entirely.
it turns out, this was the problem. i emptied the contents of the .htaccess file that was in the web folder (the one that symfony came preconfigured with) and then everything magically started working.
For me this problem was caused by cache. After clearing the cache, the new route worked fine on prod environmment (app.php), no 404's.
I ran into the same problem. I fixed the issue by first clearing the cache from the command line using the following command:
php app/console cache:clear --env=prod
After this, I removed the cache folder itself from the app directory (as I couldn't still access my bundle but only the default Symfony homepage) and then refreshed the browser and the error was gone. Hope this helps.
I've been trying to remove the E_NOTICE and E_STRICT error levels to avoid this error:
Runtime Notice: Only variables should be passed by reference
I tried modifying php.ini but didn't work, error_reporting always is -1. Then I tried setting it dynamically in the current action, and worked fine. Then I also tried the same in the first line in app_dev.php and didn't work. Which means Symfony2 is setting it dynamically somewhere.
What should I do?
EDIT
For those who are not familiar with the error:
$user = $this->('security.context')->getToken()->getUser();
$first = reset($user->getRoles()); // error
$roles = $user->getRoles();
$first = reset($roles); // works fine
Whilst the notice is not 'retarded', this is a reasonable question in other contexts so: this is set in the Kernel instance, instantiated in app_dev.php (or app.php).
The second parameter to the construct is a boolean debug flag, and if true then error_reporting is set to -1 and display_errors to 1, otherwise default and 0 respectively.
$kernel = new AppKernel('dev', false);
symfony documentation
Hope this helps.
I got the same error in the following scenario i.e.
Scenario:
I lost the development environment for my existing LIVE project. But I got the whole code from GIT repo and then installed the symfony 2.4.2 (same version as on LIVE site) in my new development environment. Then I found that the web-application pages working on the LIVE site are broken in my new DEV environment.
Solution:
I spent quit a lot time to understand why the problem is then I found that i.e.
When I installed symfony 2.4.2 in my development environment using composer.phar then it created a new web/app_dev.php file in my development environment and it has the following entry to turn it off i.e.
Debug::enable();
Just comment the above line then the php notices will be off and then all the pages that were giving me notices are fixed.
I hope this will be helpful for someone having the same problem like me. Good Luck!
Cheers.
PS: But I will recommend to enable the above line in your new development projects so that you can see the PHP notices and then remove them during development.
this is my app/autoload.php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale /Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale /Resources/stubs');
$loader->add('Stof', __DIR__.'/../vendor/bundles');
$loader->add('Gedmo', __DIR__.'/../vendor/gedmo-doctrine-extensions/lib');
$loader->add('Zend\\Search' , __DIR__.'/../src/EWZ/zends');
$loader->add('EWZ', __DIR__.'/../src/EWZ');
}
the problem is, it executes the condition on my computer (loads the classes), but not on the other computers that download it through git. when i put die in the condition, it stops for me, but not for other computers.
can anyone tell me what does the condition do? as i've been failing miserably for last two hours in resolwing the problem. thx
"The condition will be entered if the intl extension doesn't exist for the current version of PHP. It sounds as though your remote servers do have it installed, but you don't locally." RobMasters