I am trying to understand how Symfony 5 routing works.
What will happen if in my project I have 2 different controllers with the same route name?
For example, in Controller1.php:
/**
* #Route("/publisher/notification_update/")
*/
And in Controller2.php:
/**
* #Route("/publisher/notification_update/")
*/
Then from somewhere inside a twig, I have a form that calls this route as follows:
<form name="notification" id="notification{{message.notification_id}}"
action="/publisher/notification_update/" style="display:none"
method="post">
<input hidden class="hiddenNotificationsForUser" type="text" id="{{message.notification_id}}"
value="{{message.message}}" onclick="this.form.submit();" />
</form>
What will happen in this case? Will there be an error, or will it go to the first route it finds alphabetically?
In symfony 5 I have used #[Route(['/login', 'admin/login'], name: 'app_user_login')] for route two url paths for single controller action
After reproducing this scenario with Symfony 5 on a LEMP server in DigitalOcean, I found out that there is no error or warning message.
Symfony picked the route specified in Controller1.php:
/**
* #Route("/publisher/notification_update/")
*/
This, however, is a bad thing because having the situation I described combined with a large code base can lead to a very hard to identify bug.
You may never reach the route that you need even if everything is correct with it's contents.
Related
I have a route with a parameter {id} on which I want to apply a condition. Only if {id} contains more than 3 characters, this route should be available. I read about conditions in routes both in the documentation and in a similar question. What I tried:
/**
* #Route("/{id}", name="some_route", condition="strlen(id) > 3")
*/
I also tried with requirements instead of condition and tried {id} instead of id. No luck. The error that is show is:
The function "strlen" does not exist around position 1 for expression strlen(id) > 3.
How to solve this issue?
In this case, using regular expression is the best option. Take a look in the PHP documentation to find out more (Here is the link). And suppose the characters you are referring to are alphanumeric characters (I added the - and _).
<?php
// some code ...
/**
* #Route("/{id}", name="some_route", requirements={"id"="[a-zA-Z0-9_-]{3,}"})
*/
I'd like to be able to open the app and print the parameters when I click on the dynamic link (even though it's not published).
Is there a way to do this?
Yes! In fact, I go through this exact process in the getting started videoS (part 1), (part 2), which I recommend you check out if you haven't yet.
But, generally speaking, you can test the "Open my app if I have it installed" flow simply by clicking on a dynamic link. If your app is installed on the device, it should open up just fine; even if it's not a published app.
If you want to test the non-installed flow, this is pretty easy, too.
First, give your Firebase project an app store ID in your project settings. It can be any valid App store ID -- it doesn't have to be for your app.
Then generate a new dynamic link.
This time, when you click on this new link, it should take you to the app store for the ID you listed above. You don't need to actually install this app -- just making it to the app store listing is good enough.
Now, go ahead and reinstall and run your app. If everything is working properly, it should retrieve and display the dynamic link data for you.
I have faced the same issues, and after spending many hours trying to found a solution, and following the instruction to debug explained by Todd Kerpelman post, I could identify that the firebase has not sent a universal link on the first app launch and has sent the scheme URL with the following structure:
[bundle_id]://google/link/?deep_link_id=[firebase_universal_link]
After identifying that, I found the dynamicLinkFromCustomSchemeURL method inside of the Firesabe SDK and I could solve my problem on the first app launch by dynamic links.
/**
* #method dynamicLinkFromCustomSchemeURL:
* #abstract Get a Dynamic Link from a custom scheme URL. This method parses URLs with a custom
* scheme, for instance, "comgoogleapp://google/link?deep_link_id=abc123". It is suggested to
* call it inside your |UIApplicationDelegate|'s
* |application:openURL:sourceApplication:annotation| and |application:openURL:options:|
* methods.
* #param url Custom scheme URL.
* #return Dynamic Link object if the URL is valid and has link parameter, otherwise nil.
*/
- (nullable FIRDynamicLink *)dynamicLinkFromCustomSchemeURL:(NSURL *)url
NS_SWIFT_NAME(dynamicLink(fromCustomSchemeURL:));
/**
* #method dynamicLinkFromUniversalLinkURL:completion:
* #abstract Get a Dynamic Link from a universal link URL. This method parses the universal link
* URLs, for instance,
* "https://example.page.link?link=https://www.google.com&ibi=com.google.app&ius=comgoogleapp".
* It is suggested to call it inside your |UIApplicationDelegate|'s
* |application:continueUserActivity:restorationHandler:| method.
* #param URL Custom scheme URL.
* #param completion A block that handles the outcome of attempting to get a Dynamic Link from a
* universal link URL.
*/
- (void)dynamicLinkFromUniversalLinkURL:(NSURL *)url
completion:(FIRDynamicLinkUniversalLinkHandler)completion
NS_SWIFT_NAME(dynamicLink(fromUniversalLink:completion:));
/**
* #method dynamicLinkFromUniversalLinkURL:
* #abstract Get a Dynamic Link from a universal link URL. This method parses universal link
* URLs, for instance,
* "https://example.page.link?link=https://www.google.com&ibi=com.google.app&ius=comgoogleapp".
* It is suggested to call it inside your |UIApplicationDelegate|'s
* |application:continueUserActivity:restorationHandler:| method.
* #param url Custom scheme URL.
* #return Dynamic Link object if the URL is valid and has link parameter, otherwise nil.
*/
While trying to understand why my view is not displaying, I noticed the following error in the log:
I do not think it is possible to delete the URL alias from Taxonomy terms. At least I cannot find how to do this.
I have, however gone through ALL of my taxonomy terms and removed the value for this field.
I have also done the following with Pathauto:
Also, I have checked the report located at admin/reports/fields and can confirm that there are no entities that use a field called URL alias.
I have gone through each content item and ensured that they have the following setting (anyone know how to do this in bulk?). But still the error remains.
Anyone know then how I can fix this strange error?
Im not entirely sure what this command does, but it fixed the error:
drush updb --entity-updates
Since https://www.drupal.org/node/2554097, the magic in Drupal core that took care of updating entity definitions is gone. drush updb --entiy-updates is an alternative to this but it is not a silver bullet. Instead, it is safer to write database updates.
Taking the screenshot at the top as an example, here is a database update that would delete those two field definitions:
/**
* Fix taxonomy and node field definitions.
*
*/
function mymodule_update_8101() {
$manager = \Drupal::entityDefinitionUpdateManager();
if ($field = $manager->getFieldStorageDefinition('alias', 'node')) {
$manager->uninstallFieldStorageDefinition($field);
}
if ($field = $manager->getFieldStorageDefinition('alias', 'term')) {
$manager->uninstallFieldStorageDefinition($field);
}
}
Have a look at the rest of the available methods at https://www.drupal.org/node/2554097 in order to write database updates for each scenario.
use the entity_update module or the devel_entity_updates module
I have this in my routes.conf file:
# SecureSocial routes
# Login page
GET /login securesocial.controllers.LoginPage.login
And then I have this in a Scala Controller file
val index = SecuredAction { implicit request =>
Redirect(routes.UserOps.watchlist)
// how do I go straight to /login? >|
}
Doing this takes me to a login page that has a red error bar saying "you must be signed in to view this page". If I access `localhost:9000/login' I get the login page without the error bar.
Normally I do a Redirect(routes.SomeControllerObject.ActionMethodName) but in this case the controller I need to access is in a plugin...
I feel like I'm missing something rather large here...
Update:
To reverse-route to an action in a plugin controller you need to provide the correct, full path to the plugin's routes class.
Redirect(securesocial.controllers.routes.LoginPage.login)
Original Answer
For reverse-routing I don't think it matters where the Controller is since Play is building that when the project compiles. From the documentation:
For each controller used in the routes file, the router will generate a ‘reverse controller’ in the routes package, having the same action methods, with the same signature, but returning a play.api.mvc.Call instead of a play.api.mvc.Action.
So this should work just as if LoginPage was a controller directly in your app.
Redirect(routes.LoginPage.login);
In order to show the message, you must have an item in the Flash. When you hit /login directly, there is no flash, so you won't see that message.
If you want to see that message:
Redirect(securesocial.controllers.LoginPage.login).flashing( ... )
I have installed FPNTagBundle via composer. I have successfully added tags to my articles, but when I add DoctrineExtensions' TagRepository as the repositoryClass with
/**
* #ORM\Entity(repositoryClass="DoctrineExtensions\Taggable\Entity\TagRepository")
* #ORM\Table
*/
class Tag extends FPN\TagBundle\Entity\Tag
and try to use TagRepository's method getResourceIdsForTag('post', 'tagname'), it fails. I've checked the repository class with
$tagRepo = $this->getDoctrine()->getRepository('GergelyPolonkaiFrontBundle:Tag');
echo get_class($tagRepo);
and it's not TagRepository, but Doctrine\ORM\Entity\Repository. I don't have any other error message regarding the repositoryClass thing, even if I specify an invalid classname.
Have I found a bug, or do I miss something somewhere?
It seems I was hitting a bug. After merging some pull requests by Fabien Pennequin 16 days ago, it now seems working as expected.