{
  "id": "php/symfony-route-parameter-constraint-violation",
  "signature": "Symfony\\Component\\Routing\\Exception\\MissingMandatoryParametersException: Some mandatory parameters are missing (\"id\") to generate a URL for route \"user_profile\" in /var/www/app/src/Controller/UserController.php:34",
  "signature_zh": "Symfony\\Component\\Routing\\Exception\\MissingMandatoryParametersException：生成路由“user_profile”的 URL 缺少某些必需参数（“id”），位于 /var/www/app/src/Controller/UserController.php 第 34 行",
  "regex": "Symfony\\\\Component\\\\Routing\\\\Exception\\\\MissingMandatoryParametersException: Some mandatory parameters are missing \\(\"[a-z_]+\"\\) to generate a URL for route \"[a-z_]+",
  "domain": "php",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "When generating a URL from a route definition using `$router->generate()` or Twig's `path()` function, one or more required route parameters (defined in the route path) are not provided.",
  "root_cause_type": "generic",
  "root_cause_zh": "当使用 `$router->generate()` 或 Twig 的 `path()` 函数从路由定义生成 URL 时，未提供一个或多个必需的路由参数（在路由路径中定义）。",
  "versions": [
    {
      "version": "symfony 6.4",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "symfony 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "symfony 7.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "php 8.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Clearing the Symfony cache with `php bin/console cache:clear`",
      "why_fails": "The cache clear does not fix the missing parameter issue; it only refreshes the route metadata, but the call site still lacks the required argument.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding a default value for the parameter in the route definition without providing it at generation time",
      "why_fails": "If the parameter is in the route path (e.g., `/user/{id}`), it is mandatory unless a default is set in the route definition; adding a default may work but can lead to incorrect URLs if the default is used unintentionally.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Pass the missing parameter when generating the URL: `$url = $this->generateUrl('user_profile', ['id' => $user->getId()]);` or in Twig: `{{ path('user_profile', {id: user.id}) }}`.",
      "success_rate": 0.95,
      "how": "Pass the missing parameter when generating the URL: `$url = $this->generateUrl('user_profile', ['id' => $user->getId()]);` or in Twig: `{{ path('user_profile', {id: user.id}) }}`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the parameter is optional, make it optional in the route definition by adding a default value: `#[Route('/user/{id}', defaults: ['id' => null])]`.",
      "success_rate": 0.9,
      "how": "If the parameter is optional, make it optional in the route definition by adding a default value: `#[Route('/user/{id}', defaults: ['id' => null])]`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Pass the missing parameter when generating the URL: `$url = $this->generateUrl('user_profile', ['id' => $user->getId()]);` or in Twig: `{{ path('user_profile', {id: user.id}) }}`.",
    "If the parameter is optional, make it optional in the route definition by adding a default value: `#[Route('/user/{id}', defaults: ['id' => null])]`."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://symfony.com/doc/current/routing.html#generating-urls",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.89,
  "fix_success_rate": 0.92,
  "resolvable": "true",
  "first_seen": "2024-05-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}