sonata sandbox blocking the Symfony2 exceptions? - symfony

I'm trying to understand how works sonata sandbox...
I have created a new route and trigged:
php app/console sonata:page:update-core-routes --site=3
the landingpage was creaded successfuly,
then :
php app/console sonata:page:create-snapshots --site=3
theoretically all is well created,
but my route is pointing to a own controller with my own template and my own block return any response...
sure that i have done something wrong in my block or in my template, but I'm really surprised because when I do a probe to see until where the script run well... for exaple:
//in my action
$this->asdfasdfasdfasfd();
I'm no getting any response, only a white screen. somebody know why? and how can I solve?

Related

Symfony routes not working anymore

I have an application been working on for a while with a fully working login and creating new users functionalities, and out of no where i was trying to switch the user -to change the role- i wasnt able to login again. after some digging around the code i found out that 302 code status is being thrown after login and therefor the logging process stopped working.
i had this code in my SecurityController:
return new RedirectResponse('/sys-admin/');
and changing that code to this :
return $this->forward('AppBundle:SystemAdmin:index', array());
make it work and i am logged in again but now all my routes stopped working, i mean in my views there are buttons something like :
<a href="{{ path('system_admin_client') }}"
class="btn pmd-btn-flat btn-default">Go!</a>
when i click the button i am logged out and redirected to the login page and in the network tab in any browser i can see that the route sys-admin/client have status code 302 since i was logged out.
running bin/console debug:router shows me all my routes are there and for this example running bin/console router:match /sys-admin/client also shows me a match with the controller and every information.
this is how my routes looks like:
app_system_admin:
prefix: /sys-admin
resource: "#AppBundle/Resources/config/routing/sys_admin.yml"
sys_admin.yml
system_admin_client:
path: /client
defaults: { _controller: AppBundle:SystemAdmin:index}
I cant figure out to know what went wrong! any help will be appreciated. Thanks!
more info: i am using Symfony 4.0.4 and if i tried to do something like forwarding on any route its working but the redirecting is not.
The 302 HTTP status code is for a redirection, it's not an error.
It was normal since you returned a RedirectResponse.
In my opinion the problem doesn't come from the redirection.
You should put it back and check the user-switching function (or the user itself).
If you do that, don't hardcode the redirection path. Use a Symfony method to generate it, like:
return $this->redirectToRoute('system_admin_index');
I found the solution after a lot of investigating. I am using docker to make the whole app running and for some reason php-fpm logs showed no errors but the error was the php session is being broken because of no access for the user, changing to root user on docker fixed this issue since root had access.

FOSUserBundle missing parameter token for password reset issue

I have a Symfony 3 CRM, but there seems to be an issue with the password resetting (for which I am using FOS User Bundle). A user can enter their email, they get the email with a link, but when they reach the page to change their password, the following error is logged:
An exception has been thrown during the rendering of a template ("Some
mandatory parameters are missing ("token") to generate a URL for route
"fos_user_resetting_reset".") in FOSUserBundle::layout.html.twig at
line 54.
So, I checked the route in the FOSUserBundle config (bearing in mind, I have not altered this file or anything within the friendsofsymfony directory):
<route id="fos_user_resetting_reset" path="/reset/{token}" methods="GET POST">
<default key="_controller">FOSUserBundle:Resetting:reset</default>
</route>
And the URL being visited:
https://crm.mysite.co.uk/resetting/reset/sAt7xPNzW4AempvzK6m2xRRN7jI058xAQjbct7GgyqI
which as you can see clearly passes a token. I've had strange issues like this before, if for example I don't pass a default value in my route (even if there's clearly a token or some other required parameter passed) but since this is a separate bundle and is in XML rather than YML I don't know how to fix this. I'm not entirely sure why it's even throwing an error?
Any help with this appreciated.
try to view inside your console the route inside your app by doing:
bin/console debug:route
In this list you can get all available url
A possibility is that you need to call only:
https://crm.mysite.co.uk/reset/sAt7xPNzW4AempvzK6m2xRRN7jI058xAQjbct7GgyqI

Not able to display 404 error in prod environment

When I try to throw a simple throw $this->NotFoundHttpException('We do not currently have a website configured at this address. Please visit our website for more information or contact our support team');in dev environment, it works fine. But when I do the same in prod environment I get 500 server error.
Any ideas?
Here are screenshots of my dev and prod log files
Note: 500 error only happens when I use www in the url in prod env. On using any other word eg. nike, this is what i get
Here is the dev env result for the normal www.blore.eduflats.com url
According to the symfony documentation in order to return a 404 from your controller you need to do the following:
throw $this->createNotFoundException('The product does not exist');
Whereas, you have
throw $this->NotFoundHttpException
The error you are seeing is telling you that NotFoundHttpException does not exist. To fix your problem simply replace NotFoundHttpException with createNotFoundException
You call Eduflas.. UniversityResolver->NotFoundHttpException();
If you want to trhow exception like this, you should declare it.
Symfony Controller have $this->createNotFoundException('Something Not found');
You can throw 404 like this:
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException
//...
throw new NotFoundHttpException("Not found");
Use this way to be sure that Exception exist and test it.
Anyway clear your production and dev cache to be sure you use "the same code".
Last thing that come to my head - its possible you override error pages and you make something to your error.html.twig or error404.html.twig and you got different pages.
EDIT
When i enter your http://blore.eduflats.com/ i got
"array(29) { ["HTTP_HOST"]=> string(18) "blore.eduflats.com" ["HTTP_USER_AGENT"]=> s..."
Anyway your dev env. got error too so how it can work on prod env...
If you throw NotFoundException in dev you should get symfony debugger page and this error. In porduction this error is catch with ExceptionController and display blank error page (user should not see exceptions, only 500 error)

HWIOAuthBundle Symfony2 facebook login route name

Where do I find the route name for logging in with facebook? I don't want to hardcode the routes into the twig templates.
Short answer
Route name is hwi_oauth_service_redirect:
Name Method Scheme Host Path
hwi_oauth_service_redirect ANY ANY ANY /connect/{service}
So, for facebook you can generate connect route in view via:
{{ path('hwi_oauth_service_redirect', { service: 'facebook' }) }}
How to debug similar problems
I was also amazed how HWIOAuthBundle doesn't mention route name in documentation anywhere, or at least it isn't obviously stated and I couldn't find it.
When you have this kind of problem, you can use $ app/console router:debug command, which will provide you dump of all routes defined.

Routing & redirecting with iron-router

How does one do an official redirect to another route from a Template.event call using meteor and Iron-Router. I seem to, at least with the Dev branch run into the same error
`if (this._isRunning) // 174
throw new Error('Already in a page run'); `
As an example, i have a button that on click calls Router.go('/home'); if i run this, i get the 'already in a page run' error. Anyone else routing with the router go method?
Its actually the 'this.redirect('/anotherpath')' that causes the problem. Is there way to stop the current running page run and redirect to another route?
It looks like you're working off of the dev branch. The code you were working with has been rolled back because it wasn't working properly. If you still have the issue let me know, and sorry about that!
The code below will stop the current route controller from running (stop any downstream hooks and the action method from being run) and call Router.go('/anotherpath') which will cause a new route to run.
this.redirect('/anotherpath')

Resources