I'm converting a Symfony 3.4 site to 6.1. I created a brand new 6.1 site and am copying elements over 1-by-1. I'm using Attributes to define routes inside Controllers (no changes to routing.yaml).
I was working on some fixes in the CustomerController, when suddenly I started getting route does not exist errors for the routes inside that Controller. All other routes are working perfectly. Routes within this Controller were previously working perfectly.
I ran bin/console debug:router and sure enough, the routes inside the CustomerController are missing. However, the CustomerController.php file is still there, it has the correct permissions, as far as I can tell there are no syntax errors, but even if there were, I should be able to see the syntax errors instead of route does not exist errors, no?
As far as I can tell, Symfony is simply ignoring the existence of the CustomerController.php file. How can that be? How can I get it to include it again?
I have run bin/console cache:clear but it had no effect on this.
EDIT: I deliberately introduced a syntax error into the CustomerController.php file and refreshed the page in the browser, sure enough Symfony showed me the syntax error. I fixed the syntax error and the error went back to route does not exist - even though the route does exist in the CustomerController.php file and was previously working.
There is no further information in the log file other than the missing route exception.
EDIT2: Here's the first route and function in the Controller:
#[Route('/sales/customer', name: 'customer')]
public function index(): Response
{
return $this->render('customer/list.html.twig', [
'controller_name' => 'CustomerController',
'list' => 'customer'
]);
}
Try to fetch the links as a loop inside you template file (Twig). Something like this:
{% for post in posts %}
<a href={{ path('post_show', {'id' : post.id}) }}>
<p>Anytext here</p>
</a>
{% endfor %}
Any list will appear?
I eventually managed to reverse out the changes I had been making, and saw that I had deleted use Symfony\Component\Routing\Annotation\Route; - putting this back solved the problem! Shame that Symfony can't alert you to this kind of problem...
Related
I have my site running on a CentOS server, and list view is fine, but when I click on a link to go to a detail view, I now get a Server Error (500).There are no errors in the nginx logs, and I don't know where else to look to debug these. I have just upgraded to django 3, I'm suspecting there is something that I have not corrected for the upgrade, but I don't know what that would be as I am not getting any error messages or stack trace, just Server Error (500). What can I do to find the issue please?
You're probably aware of it, but have you activated Debug mode in the settings.py? So far I always got a very detailed error report on reload when I broke something. Did you change any of the models? I would make sure that your migrations are up to date and you don't ask for any unnamed variables, but you probably already know that.
SOLVED: Whilst I thought I had changed all the
{% load staticfiles %}
to
{% load static %}
I had missed one that was in an extended template that required this tag. Changing that too solved the issue. There was one other issue that was affecting this site and giving a Server Error (500) on another page too, and that is that in django 3.0, it looks like they are enforcing styling also, so I had to change:
{% static 'project_portal/images/icon_add_circle.png'%}
by adding a space between the last ' and the % so this:
{% static 'project_portal/images/icon_add_circle.png' %}
I am usually quite ocd about my styling but I missed this and it's now an issue in Django 3.
I'm useing yoeman aspnetcore-spa template with angular 2.
basically, there are 3 files:
app.module.client.ts
app.module.server.ts
app.module.shared.ts
I've put my Service in the providers in app.module.client.ts then added my routing in app.module.shared.ts. Which all work and great and I could navigate to it but when I try to replace redirectTo with my new path. Which at this point is still ok but when I enter the page from localhost:5000 the console screams with error:
fail: Microsoft.AspNetCore.NodeService[0] blah bla Uncaught (in promise): Error: No provider for NameService!
and some at injectionError
if I change redirectTo: 'home' then it works and I could navigate to my page. What's worse is when I have { useHash: true } it won't stop logging errors in the terminal.
I've tried using Router to navigate to my page in HomeComponent ngOnInit() which kind of works but still has problem when i enter the page from localhost:5000. What I haven't tried is replacing HomeComponent with mine instead.
What I really want is to understand what is going on. Honestly, I'm new to this template, normally there's just one app.module.ts. There is something in this template I don't understand. Please, help!
I've figured out a work around. This template does not have the usual UniversalModule, may be that's where things went wrong. I'm not sure if it's the best way to solve it but my work around is:
adding my service in app.module.server.ts as well. This is because I was thinking the home page was first rendered on the server.
inject ORIGIN_URL in my service. I thought I might have to do similar things to app.module.client.ts and it worked. So, in the constructor of my service i've added #Inject('ORIGIN_URL') private _originUrl: string and in my http method I prefix my url with this._originUrl.
I'm creating custom error pages for the 404 and 500 error in my Symfony project. I would like to know how to internationalize those pages.
What I mena by thta is that I already know how to use {% trans %} in my twig and how to create the file whit the translated texte. What I
Usally, my urls look like that: kevinduguay.ca/en/..... but in the case of an error page, /en might not be there, but I still need to find in what language I should siplay the page. Maybe the language of the country?
Hope you can help me.
by following this cookbook, you can find current local in error page by:
$request->getLocal();
Although you dont nedd to this, trans() method detect current local
I've configured SonataMediaBundle, added relation to Media in my Entity. Admin for entity works fine until I add this snippet from docs:
twig:
form:
resources:
# other files
- 'SonataMediaBundle:Form:media_widgets.html.twig'
After that all I get is this error:
FatalErrorException: Compile Error: Cannot inherit previously-inherited or override constant MARKER from interface Doctrine\Common\Persistence\Proxy
What I'm doing wrong? How to make sonata_media_type work with its widget template?
googling for somedays for a similar error I came up with the conclusion that is has nothing to do with your code, but is some kind of strange bug in environment, more likely in APC.
Check this post if you are using amazon server: https://forums.aws.amazon.com/message.jspa?messageID=508800
After I did that upgrade the problem solved. I'm still waiting to see if it comes out again, because it was not a permanet error, and after each apache reload/restart it went away for a while...
Other op-caches may solve the problem without loosing performance.
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