{"record":{"id":"5f89ee469f9cfdc4","repo":"phalcon/cphalcon","slug":"it-s-necessary-to-define-the-route-name-with-the-p","errorCode":null,"errorMessage":"It's necessary to define the route name with the parameter 'for'","messagePattern":"It's necessary to define the route name with the parameter 'for'","errorType":"exception","errorClass":"Phalcon\\Mvc\\Url\\Exceptions\\MissingRouteName","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Url.zep","lineNumber":147,"sourceCode":"        if local == null {\n            if typeof uri == \"string\" && (memstr(uri, \"//\") || memstr(uri, \":\")) {\n                if preg_match(\"#^((//)|([a-z0-9]+://)|([a-z0-9]+:))#i\", uri) {\n                    let local = false;\n                } else {\n                    let local = true;\n                }\n            } else {\n                let local = true;\n            }\n        }\n\n        if typeof baseUri != \"string\" {\n            let baseUri = this->getBaseUri();\n        }\n\n        if typeof uri == \"array\" {\n            if unlikely !fetch routeName, uri[\"for\"] {\n                throw new MissingRouteName();\n            }\n\n            let router = this->router;\n\n            /**\n             * Check if the router has not previously set\n             */\n            if unlikely !router {\n                let container = <DiInterface> this->container;\n\n                if unlikely typeof container != \"object\" {\n                    throw new RouterServiceUnavailable();\n                }\n\n                if unlikely !container->has(\"router\") {\n                    throw new RouterServiceUnavailable();\n                }\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Url.zep#L129-L165","documentation":"Phalcon\\Mvc\\Url::get() has a dual API: a string URI is returned prefixed with baseUri, but an array is interpreted as a named-route lookup that MUST contain a 'for' key naming the route (see phalcon/Mvc/Url.zep:147). If the fetch of uri['for'] fails, MissingRouteName is thrown because there is no route name to resolve against the router.","triggerScenarios":"$url->get(['param' => 1, 'id' => 5]) intending query-string params but omitting 'for'; using 'name' or 'route' as the key instead of 'for'; building the array dynamically so the 'for' entry is conditionally dropped.","commonSituations":"Assuming Url::get(array) appends a query string (it does not — query args go as the second parameter); typos in the magic 'for' key; array_merge/array_filter accidentally removing the key.","solutions":["Add 'for' => '<route-name>' as the first entry of the array, keeping other entries as pattern placeholders","For plain paths with query params, pass a string URI and use the second argument: $url->get('products/search', ['page' => 2])","Verify with isset($uri['for']) before calling when the array is built dynamically"],"exampleFix":"// before\n$link = $url->get(['controller' => 'posts', 'action' => 'show', 'id' => 7]);\n\n// after\n$link = $url->get(['for' => 'post-show', 'id' => 7]); // named route with {id} placeholder","handlingStrategy":"validation","validationCode":"if (is_array($uri) && !isset($uri['for'])) {\n    throw new \\InvalidArgumentException(\"Url::get() array URI requires a 'for' key naming the route\");\n}","typeGuard":"function isNamedRouteUri(mixed $uri): bool\n{\n    return !is_array($uri) || array_key_exists('for', $uri);\n}","tryCatchPattern":null,"preventionTips":["Remember array URI = named route lookup, string URI = path","Query params go as the second argument to Url::get()","Centralize URL building in helpers that always set 'for'"],"tags":["phalcon","url","router","named-routes","api-misuse"],"backgroundTag":"missing-required-parameter","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}