When I use the dev AppKernel of my app symfony shows a profiler bar at the bottom of the site.
How does symphony does this? Does it transparently inject something into my templates? I ask this because when I output raw text with "return new Response" from a controller action no profiler code is appended.
Web profiler is injected during event kernel.response.
Precisely it's caused by WebDebugToolbarListener.php.
It checks if response content type is html and there's no xdebug token header.
Related
I just installed the Symfony 4.1, the dump function doesn't work on controller but it works on twig files, if I remove the symfony/debug-bundle, then the dump works correctly in controller but it doesn't work in twig properly, it acts like simple var_dump.
Does any body have any idea why this is happening?
Symfony have new features for dump.
Now dump shown in symfony profiler.
Please check proper. In symfony profiler
This problem is fixed with symfony 4.1.1, https://github.com/symfony/symfony/releases/tag/v4.1.1
dd() in controller work after upgrate to 4.1.1 with composer "php composer update".
Just be careful, if you use dump in controller, then you should have WebProfilerBundle installed as well. Then you see output inside of that toolbar and not in page content.
I had the same problem just now and the other answers here were not relevant. If you look to the Profiler Bar, the "crosshairs(debug)" icon will show your dump from twig only (sometimes).
To see ALL dumps, you sometimes need to go track them down in the "Ajax Requests" part. To do this, click the Ajax Requests in the Symfony Profiler bar at the bottom of the screen. Then click the lines until you see a AJAX request that fired and has your dump.
The reason why only your Twig dump showed up is that the profiler bar is mostly about the primary request. The suppression is an ajax secondary request. The dump you asked about was in the ajax not the primary request.
I would like to track the users on my Symfony 2.7 page using Piwik.
Piwiks default tracking option is the integration of a small JavaScript into the webpage, e.g. with the page footer. Of course this could easily be done by adding the code to the base Twig template.
However I would like to avoid the usage of JavaScript. My Symfony page and the Piwik page both run on the same server. Actually I am surprised that letting the client communicate with Piwik (over Javascript) is the recommended option instead of a direct way to let the webpage server talk to Piwik.
I think the Tracking HTTP API and the PHP Client are what I am looking for. However I am not sure on how to integrate this into Symfony.
I managed to connect my Symfony page with Piwik, however I wonder if this the right/best way to do it:
Used composer require "piwik/piwik-php-tracker" to add the PHPTracker to my Symfony project
Added a new Service that is responsible to create and manage a PiwikTracker object. The Service makes different methods of the Tracker, e.g. doTrackPageView() available to the rest of the project.
Added a new Twig function which uses the Service to trigger the doTrackPageView() method.
Added a call to this function to my base template
This works fine: Page views are correctly reported to Piwik and recorded without any problem. Of course I could easily add other methods to track events, actions, etc.
But: I am really surprised that I could not find any ready-to-use solution for this. Did I miss anything or is this the indented way to use Piwik with Symfony?
Following the lead of the cookbook:
http://symfony.com/doc/master/cookbook/controller/error_pages.html
The custom error pages are never rendered in production. If I understand correctly the problem is shared by many on the web. Does anyone know of a method that really works?
You can create custom exception listener which will for example render some template.
See the similiar post: Symfony2 Custom Error Exception Listener - Rendering templates or passing to a controller
Is there anyway to detect browser version in symfony prior to loading any pages and then run a corresponding action? I was thinking of using modernizr, but I was hoping to not have to rewrite all my views.
Basically what I was hoping I could accomplish is that before the framework attempts to match the url to a route it would first check to see if the user has a particular browser version and if not run another controller instead of the the controller defined in the route.
I think what your suggesting is not a "best practice". I'm assuming you want to route a mobile request to a unique Action method in a Controller. You really shouldn't have a separate controller based client device. This is the job of the (V)view in MVC.
Modernizr is a client side solution with css,js but if youre using symfony, i would prefer server side and that requires the title of this question.. "Detecting browser on request".
While you can custom configure your app to detect the device(and its not to hard), there's also an easier option. Try this bundle. https://github.com/suncat2000/MobileDetectBundle . It does everything and allows for you to make both controller modifications or make twig aware of the browser so you can make smaller changes.
We have recently started moving over to ASP.NET MVC 3 from webforms. There is a PDF export utility that was written to take a page path (url) and render the html using the HttpServerUtility.Execute method. http://msdn.microsoft.com/en-us/library/k8e2dw5s
This works fine when the url being requested is a webform, but when the it is an MVC action we just get the error "Error executing child request for /MyControllerName/MethodName.". When debugging our IDependencyResolver class and controller constructor never get hit, so it isn't the action that is failing.
What are we doing wrong? Is there another way to make a server side request from the current context to get the html output of an MVC action?
Have you looked at this:
http://connect.microsoft.com/VisualStudio/feedback/details/102401/httpserverutility-throws-httpexception-in-attempt-to-transfer-from-httphandler-httpmodule-to-another-httphandler