How to customize 403 error exception in symfony2? - php

I have put the following files in
/app/Resources/TwigBundle/views/Exception
error.html.twig, error.json.twig , error403.json.twig, error404.json.twig
But still i am not able to get those templates
I want it for access denied exception
Token does not have the required roles.
403 Forbidden - AccessDeniedHttpException
1 linked Exception:
AccessDeniedException ยป

If i were you i'd customize the error403.html.twig in the following folder app/Resources/TwigBundle/views/Exception/error403.html.twig
I guess you've mistaken the format of this file (json instead of html)
Also, make sure that you've cleared the cache (php app/console ca:cl) and that you are in prod environement.

A more recent update for this. I found that in Symfony 2.8.x, the template you need to override is called exception.html.twig.
I did so by adding the following file in this path.
app/Resources/TwigBundle/views/Exception/exception.html.twig
You can find the original in this folder here:
vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/views/Exception

Related

404 route not found exception handling in symfony

I want to create a template for page not found. whenever 404 no route found exception is throwing need to redirect to page. As that is not in proper UI way. I tried steps from this URL
https://symfony.com/doc/current/controller/error_pages.html
I am new to symfony . followed steps until service.yml and created customExceptionController.php and I dont know what to do next step and I am getting error like
How to fix this issue.Please anyone help me to get out of this issue. Thanks in advance
In the dev environment, you will always see the default exception page which is meant to ease debugging issues. If you want to see how a certain error page looks like in the prod environment (because you maybe created a custom template for it), you need to access a special URL that is only available for this purpose in the dev enviromnent (see https://symfony.com/doc/current/controller/error_pages.html#testing-error-pages-during-development). In your case, this URL is http://127.0.0.1:8000/_error/404

Laravel 5.6 Reoccuring Error

I have an error that occurs no matter what the actual error is within Laravel 5.6 It just keeps saying Could not find resource 'views/layouts.html.php' in any resource paths.(searched: /var/www/{domain}/vendor/filp/whoops/src/Whoops/Handler/../Resources) for everything that causes an error and doesn't display the full debug page that Laravel usually displays. I'm not sure what caused this or what I could do to fix it besides reinstalling Laravel, which I'd highly prefer not to do. Does anybody have any ideas what file I might be missing or what might be causing this?
Image of full error: https://i.imgur.com/5dFhlYg.png
why you use layout.html.php. Laravel has a template engine blade. you can use layout.blade.php
You Need to use views.layout. example:
return view('views.layout');
But note there are views is a folder name. if you create a folder under views folder then you can call views folder. Laravel default views folder is views don't need to call on return path.

failed to open stream php error when loading stories from storyblok in twig

Currently I am using the silex boilerplate from the storyblok github repository, where I load the stories via the getStories function.
My code looks like this:
{%
set reference = getStories(global('references_path'), 1, 0, options('{"filter_by[customer_name]":"' ~ item.customer_name ~ '"}'))
%}
This code is called from another twig component in a loop.
For one "reference" I do get this error message:
file_put_contents(../cache//c3RvcnlibG9rOnN0b3JpZXMvYTo0OntpOjA7czoxMDoiRXJkZ2FzIE/DliI7aToxO3M6MTE6ImRlL3Byb2pla3RlIjtpOjI7aToxO2k6MztzOjM6ImZzcCI7fQ==):
failed to open stream: No such file or directory in
/webapp/vendor/apix/cache/src/Files.php
Seems to be an Issue with the cache.
Thanks in advance.
The path which will be generated in your case contains a /. So PHP can't create the file because it would be in an not existing folder.
We can see that this issue is in the Files.php of the Apix/Cache we are using to allow different caching options for the silex boilerplate. Nevertheless, we've found a way to fix this issue by now - but we will create a new pull request for the Apix/Cache so it will check for / before saving.
For you this means:
composer update
to install our new php-client version v1.1.11.

Creating custom error page in Symfony 2.5

I am working with Symfony 2.5.3 and I am trying to create the custom error page so for example if someone lands on a page or try to access a page that does not exist the 404 error message should appear within the theme of the site.
I understand that default 404 error page sits inside the TwigBundle that comes with symfony and looking at some other answers on this site people are suggesting that in order to have the custom error page I need to copy them in directory ROOT app/Resources/TwigBundle/views/Exception so I copied over the error.html.twig and even created error404.html.twig but this does not work. I also looked into this solution but still no luck.
I tried to access my development site via http://127.0.0.1:8000/app.php/services to check may be in production i will see the correct template but I dont, please note that i have cleared the cache before accessing http://127.0.0.1:8000/app.php/services and I still see the default error template that comes with Symfony
I will really appreciate any help on this.
First double check this :
Check if you're custom error template is in app/Resources/TwigBundle/views/Exception folder
Then double check the name of you're custom error template if it is error.html.twig OR/AND error404.html.twig
Then create the custom error/template that you want users to see
You can see the custom error/page when you view the website via app.php which is a production environment.
Beetween each check
rm -rf app/cache/*
It should works now ;)
Another way to easily test your custom error template in dev mode is to use instead WebfactoryExceptionsBundle who provide a test controller for displaying your custom error page even when kernel.debug is set to true.

About CodeIgniter 403 Error

I just recently got a project based on CodeIgniter and I am total beginner.
I have added new view in my CI views and I want to load it to popup window when I press on a given link. But I get that my playerview.php page is forbidden on this server error 403. So where should I edit or change settings so that I have permission to use my new view?
The .htaccess file has only one line and it says
Deny from all
You can't call a view directly from a browser. Views are loaded by controllers, and controllers are called based the URL. It is typically www.yoursite.com/controllername/functionname
If you read the general topics section of the CI docs, it will all make sense.

Categories