Symfony 4.4 - Custom Error Templates Not Working - symfony

I've got an issue when it comes to using Custom Error Templates in Symfony 4.4 Flex. Everything has been set properly according to the guide from https://symfony.com/doc/4.4/controller/error_pages.html
I can access the Custom Error Templates via /_error/{errorCode} when I run the application with APP_ENV=dev - but if I change APP_ENV to prod (with APP_DEBUG set to false/0 of course), I get the default Symfony "500 Internal Server Error" page. I even tested it after deploying the application on the remote host, and it's the same issue when I try to access /random-unexisting-page (already got the error404.html.twig template set and it works on 'dev' via /_error/404).
I want to know, does it have anything to do with other configuration within /config/ ? Have you got any idea what the issue could be ?

I made a few tries and I think I've understood your problem.
So when you want to create a personalized error page, first you need to add, under the template directory, the following path, same as your link said
templates/
└─ bundles/
└─ TwigBundle/
└─ Exception/
├─ error404.html.twig
├─ error403.html.twig
└─ error.html.twig # All other HTML errors (including 500)
The most common error is the 500 so you can add this: error500.html.twig or just leave the generic one, it's up to you.
The importamt thing is that whenever you add a file error in the directory or you simply make a change in an existing file: you MUST launch the command to clear the cache (you can only launch this command when the project has no errors). If you don’t do this the changes wont be visualized.
STEPS:
fix the error or start from a previous working build
launch the clear command: php bin\console cache:clear,
you'll get something like that result_of_clear_cache
refresh the page and you should see the new page
PS. if you need some visual references:
path
error_file
result_on_browser

Related

How to solve this error in moodle ? and setup in localhost?

Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.
You need to check 'config.php' in your moodle installation files directory.
There you can find a line like below, which shows your directory name (it seems empty as per your error, you need to define path here) - in this directory/folder your moodle media uploads get store.
$CFG->dataroot = '/var/moodledata';
Moreover, after define this you will require to give Read,Write,Execute permissions to this folder.
(here '/var...' mentioned as Ubuntu directory structure, in localhost you need to mention respectively)

setting symfony for local development on herkou

I am trying to set up my symfony 2.8 app for local development.(Following - https://symfony.com/doc/current/deployment/heroku.html)
Added In proc file
web: bin/heroku-php-apache2 web/
Error
bin/sh: vendor/bin/heroku-php-apache2: No such file or directory
Also note , composer.phar config bin-dir is bin
Anyone who can share how they resolved this problem?
First of all, have you tried letting heroku create the Procfile itself? I think lately it was smart enough to work out the root of the Symfony project.
If that doesn't work, maybe that's not the right path, try:
echo 'web: $(composer config bin-dir)/heroku-php-apache2 web/' > Procfile
If none of those work, I'd rather use the heroku information on how to deploy your Symfony app, have a look at this and see if it helps:
https://devcenter.heroku.com/articles/getting-started-with-symfony

django cms tries to import unrelated project

Following this tutorial on windows: https://github.com/divio/django-cms-tutorial/blob/master/Step%201%20-%20Initial%20Setup.md
typing this line:
djangocms -p . my_site
I have this error:
OSError: Could not import settings 'ira_site.settings'
(Is it on sys.path? Is there an import error in the settings file?):
No module named 'ira_site'
ira_site is the name of an unrelated django (no-cms) project.
I've grepped (using ransack) the whole "c:\python34" and "virtual_env" folders to look for "ira_site". Not a trace of it.
I've opened every settings.py file I could open. To check of installed apps.
Not trace of it. Why would djangocms installer try to import the settings of a totally unrelated django project ? What am I missing ?
Allright, it was quite stupid. In case someone has the same problem:
your environment variables:
DJANGO_SETTINGS_MODULE
Must be set so django-admin.py can find it ( as the installer is also creating the project ). What I did is:
reset it to global-settings.py
run the installer.
And once installation was over, put it back to the settings.py file of the newly created site.

Django CMS - Template Does Not Exist Error while creating first page

I followed the instructions for installing Django CMS on my mac. When I run "manage.py cms check", everything is fine, except it says it cannot find the template_1.html. When I go into the admin to create a page, the template is in the Template drop down. When I try to save the page it gives me "TemplateDoesNotExist at /admin/cms/page/add/".
Maybe it's noteworthy, I was having issues with the url prior to this error. I was not able to open the admin or even get main page to render in the browser. After searching stack overflow I found the same issue. I changed the url patterns from the "urlpatterns = i18n_patterns" to the standard. That worked. Now I have this issue. Any assistance would be appreciated. Thanks.
Link to Traceback if needed:
http://dpaste.com/hold/1430437/
I had the same error (on Ubuntu 12.04)
Following the django-cms 2.4.3 installation instruction,
django-admin.py startproject myproject
creates a directory myproject (in which manage.py resides) and a subdirectory, also named myproject, which contains the setting files and the templates directory.
I don't know if this is the intention of the authors of the django-cms doc. But the instruction
os.path.join(PROJECT_PATH, "templates"),
in the TEMPLATE_DIRS setting points to /absolute/path/to/myproject/templates.
This should be changed to:
os.path.join(PROJECT_PATH, "myproject/templates"),
to point to the correct directory /absolute/path/to/myproject/myproject/templates

Symfony Warning : rename (../app/cache/dev , ../app/cache/dev_old ) : Access Denied . (Code : 5)

I am working on Symfony project.
When i try to do :
php app/console cache:clear
i get the following ErrorException:
Warning : rename (../app/cache/dev , ../app/cache/dev_old ) : Access Denied . (Code : 5) in ../vendors/Symfony/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php on line 76
What is the problem here? I have given all permissions to the user on my machine (Windows 7 OS). Any ideas why it is happening?
Thank You.
Be sure that the files are not in use (as meze pointed out). If you're using something like TortoiseGit or Netbeans, etc - be sure to mark the cache folder as ignored so that they are not accessed.
If all else fails, download a free program like Unlocker that will allow you to quickly and easily detach running processes from the files/folders you are trying to modify.
To expand on leek's post, Symfony 2 cache-clearing operations shuffle the cached items across different folders during the cleanup. Part of this process includes creating cache/dev-new/ and cache/dev-old/ folders.
If you are using Eclipse or another IDE that dynamically monitors subfolders within your project, the IDE will nearly instantly spot the new folder creation and look in those folders for new files (in Eclipse, I noticed the DLTK module constantly doing this in the Progress View). This may unfortunately get in the way of Symfony, which wants to rename and/or delete these folders.
Specifically with Eclipse Indigo on Windows 7 64-bit, you can remove the cache/, cache/dev/, cache/dev_old/ and cache/dev_new/ folders from the build path by right-clicking your project and selecting "Build Path > Configure Build Path...". This originally had no effect for me; I kept seeing the DLTK module trying to index the cache folders. I ended up uninstalling the Aptana Studio plug-in, closing all Editor documents, shutting down Eclipse, manually deleting the sub-folders in the cache/ folder, running Symfony cache:clear, then starting up Eclipse and reinstalling Aptana. Seems to have worked thus far.
It's an issue with Symfony 2.0.x and Symfony 2.1.x. These a workaround for this:
Open the file: src\Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand.php
and add the statement sleep(1); where the directory creation is failing, in the execute() function:
//...
rename($realCacheDir, $oldCacheDir);
sleep(1);
rename($warmupDir, $realCacheDir);
//...
You might have to re-open the CLI twice and run cache:clear, but it will fix the problem after that
If you're using text editors as Sublime Text try to ignore path of cached files
Go to Preferences/Setting
edit config file
{
...
"folder_exclude_patterns": ["var","node_modules", ".git"],
...
}
in my case
Cache folders containers.
Symfony 4
/var
Symfony 2
/app/cache
Nice coding!
I had the same issue with Symfony 4.1.13 and the root cause was that the VS Code was using the file "var/cache/dev/srcDevDebugProjectContainer.xml4QSKuA".
The issue was Cannot rename "var/cache/dev/srcDevDebugProjectContainer.xml4QSKuA".
I fix it adding **/var on the fields "Files to Exclude"
See the following steps:
1º Step:
2º Step search for "exclude" word, then add **/var/cache as the following image:
It's worked for me.
To have tranquility once and for all I create clear.bat file in MyProject folder under Windows 7 .
rmdir d:\symfony\framework-standard-edition\app\cache\ /S /Q
I guarantee 100% effectiveness for cleaning cache. Some minor problems can occurred after first time refresh website: Symfony must recreate some folders they need.
SYMFONY AND ANTIVIRUS
Multiple symfony calling in local windows machine get cross with some Antivirus software such as NOD in my case. Exclude symfony cache folder from real time protection

Resources