{"id":369818,"date":"2023-02-24T11:33:17","date_gmt":"2023-02-24T11:33:17","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=369818"},"modified":"2023-06-27T10:53:47","modified_gmt":"2023-06-27T10:53:47","slug":"generate-symfony-route-in-prestashop-module","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/","title":{"rendered":"Generate Symfony route in PrestaShop module"},"content":{"rendered":"\n<p>In this blog, we are going to learn how to&nbsp;<strong>generate Symfony route in PrestaShop module<\/strong> from the <strong>legacy controller<\/strong>.<\/p>\n\n\n\n<p>When your application receives a request, it calls a controller action to generate the response. The routing configuration defines which action to run for each incoming URL. It also provides other useful features, like generating SEO-friendly URLs.<\/p>\n\n\n\n<p>When the module is using legacy controllers, the legacy controllers do not have access to the Symfony container or router. So in PrestaShop <strong><code>Link<\/code>&nbsp;object <\/strong>has helpers to help generate urls related to Symfony controllers and routes.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. <strong>Using router via Link::getUrlSmarty<\/strong> (Available from PrestaShop 1.7.0)<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nuse Link; \/\/ at the top of PHP file\n\n\/\/ Generate url with Symfony route\n$symfonyUrl = Link::getUrlSmarty(&#091;\n    &#039;entity&#039; =&gt; &#039;sf&#039;,\n    &#039;route&#039; =&gt; &#039;admin_product_catalog&#039;,\n]);\n\/\/ This will open admin product listing\n\n\n\/\/ Generate url with Symfony route and arguments\n$symfonyUrl = Link::getUrlSmarty(&#091;\n    &#039;entity&#039; =&gt; &#039;sf&#039;,\n    &#039;route&#039; =&gt; &#039;admin_customers_edit&#039;,\n    &#039;sf-params&#039; =&gt; &#091;\n        &#039;customerId&#039; =&gt; 4,\n    ],\n]);\n\/\/ This will open customerId 4 for editing<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2. <strong>Using router via $link-&gt;getAdminLink<\/strong> (Available from PrestaShop 1.7.5)<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nuse Context;\n\n$link = Context::getContext()-&gt;link;\n\n\/\/ Generate url with Symfony route\n$symfonyUrl = $link-&gt;getAdminLink(\n     &#039;AdminOrders&#039;,\n     true,\n     &#091;&#039;route&#039; =&gt; &#039;admin_orders_index&#039;]\n);\n\n\/\/ Generate url with Symfony route and arguments\n$symfonyUrl = $link-&gt;getAdminLink(\n    &#039;AdminProducts&#039;, \n    true, \n    &#091;\n        &#039;route&#039; =&gt; &#039;admin_product_unit_action&#039;,\n        &#039;action&#039; =&gt; &#039;delete&#039;,\n        &#039;id&#039; =&gt; 42,\n    ]\n);<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3. Javascript routes<\/h4>\n\n\n\n<p>To generate a Symfony route in javascript, you can use the <a href=\"https:\/\/github.com\/PrestaShop\/PrestaShop\/blob\/8.0.x\/admin-dev\/themes\/new-theme\/js\/components\/router.ts\" target=\"_blank\" rel=\"noreferrer noopener\">router component<\/a>.<\/p>\n\n\n\n<p>The below snippets show an example :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">import Router from &#039;@components\/router&#039;;\n\nthis.router = new Router();\nconst route = this.router.generate(&#039;my_route&#039;, {parameters});<\/pre>\n\n\n\n<p>It however uses a computed file that you might need to recompute if you modified some route settings.<\/p>\n\n\n\n<p>You can recompute it using the below command :<\/p>\n\n\n\n<p><code><strong>php bin\/console fos:js-routing:dump --format=json<\/strong><\/code><\/p>\n\n\n\n<p>And put it in <\/p>\n\n\n\n<p><strong><code>admin-dev\/themes\/new-theme\/js\/fos_js_routes.json<\/code><\/strong><\/p>\n\n\n\n<p><br>This is how we can generate Symfony route in PrestaShop module.<\/p>\n\n\n\n<p>That\u2019s all.<\/p>\n\n\n\n<p>If you are facing any issues or doubts in the above process, please feel free to contact us through the comment section.<\/p>\n\n\n\n<p>I would be happy to help.<\/p>\n\n\n\n<p>Also, you can explore our&nbsp;<a href=\"https:\/\/webkul.com\/prestashop-development\/\" target=\"_blank\" rel=\"noreferrer noopener\">PrestaShop Development Services<\/a>&nbsp;and a large range of quality&nbsp;<a href=\"https:\/\/store.webkul.com\/PrestaShop-Extensions.html\">PrestaShop Modules<\/a>.<\/p>\n\n\n\n<p>For any doubt contact us at&nbsp;<a href=\"mailto:support@webkul.com\" target=\"_blank\" rel=\"noreferrer noopener\">support@webkul.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we are going to learn how to&nbsp;generate Symfony route in PrestaShop module from the legacy controller. When your application receives a request, it calls a controller action to generate the response. The routing configuration defines which action to run for each incoming URL. It also provides other useful features, like generating SEO-friendly <a href=\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":386,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[209],"tags":[2065,4126],"class_list":["post-369818","post","type-post","status-publish","format-standard","hentry","category-prestashop","tag-prestashop","tag-prestashop-1-7"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Generate Symfony route in PrestaShop module - Webkul Blog<\/title>\n<meta name=\"description\" content=\"In this blog, we are going to learn how to\u00a0generate a Symfony route in PrestaShop module from the legacy controller.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Generate Symfony route in PrestaShop module - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"In this blog, we are going to learn how to\u00a0generate a Symfony route in PrestaShop module from the legacy controller.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-24T11:33:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-27T10:53:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Vineet Kr. Gupta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vineet Kr. Gupta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/\"},\"author\":{\"name\":\"Vineet Kr. Gupta\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/bb871a3e8dd81b2b0a1690f195da6208\"},\"headline\":\"Generate Symfony route in PrestaShop module\",\"datePublished\":\"2023-02-24T11:33:17+00:00\",\"dateModified\":\"2023-06-27T10:53:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/\"},\"wordCount\":240,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"prestashop\",\"Prestashop 1.7\"],\"articleSection\":[\"prestashop\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/\",\"url\":\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/\",\"name\":\"Generate Symfony route in PrestaShop module - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2023-02-24T11:33:17+00:00\",\"dateModified\":\"2023-06-27T10:53:47+00:00\",\"description\":\"In this blog, we are going to learn how to\u00a0generate a Symfony route in PrestaShop module from the legacy controller.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Generate Symfony route in PrestaShop module\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/bb871a3e8dd81b2b0a1690f195da6208\",\"name\":\"Vineet Kr. Gupta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b8dd0faa3589c82d64586b71a9e84be11a8b9a8f3b74bb952442b904af1c68f2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b8dd0faa3589c82d64586b71a9e84be11a8b9a8f3b74bb952442b904af1c68f2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Vineet Kr. Gupta\"},\"description\":\"Proficient Software Engineer specializing in PrestaShop, with expertise in Mobile App Development, eCommerce Platform Development, and POS services. Delivers innovative, user-focused solutions that enhance functionality and drive efficient business operations.\",\"url\":\"https:\/\/webkul.com\/blog\/author\/vineetkr-gupta008\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Generate Symfony route in PrestaShop module - Webkul Blog","description":"In this blog, we are going to learn how to\u00a0generate a Symfony route in PrestaShop module from the legacy controller.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/","og_locale":"en_US","og_type":"article","og_title":"Generate Symfony route in PrestaShop module - Webkul Blog","og_description":"In this blog, we are going to learn how to\u00a0generate a Symfony route in PrestaShop module from the legacy controller.","og_url":"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2023-02-24T11:33:17+00:00","article_modified_time":"2023-06-27T10:53:47+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Vineet Kr. Gupta","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Vineet Kr. Gupta","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/"},"author":{"name":"Vineet Kr. Gupta","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/bb871a3e8dd81b2b0a1690f195da6208"},"headline":"Generate Symfony route in PrestaShop module","datePublished":"2023-02-24T11:33:17+00:00","dateModified":"2023-06-27T10:53:47+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/"},"wordCount":240,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["prestashop","Prestashop 1.7"],"articleSection":["prestashop"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/","url":"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/","name":"Generate Symfony route in PrestaShop module - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2023-02-24T11:33:17+00:00","dateModified":"2023-06-27T10:53:47+00:00","description":"In this blog, we are going to learn how to\u00a0generate a Symfony route in PrestaShop module from the legacy controller.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/generate-symfony-route-in-prestashop-module\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Generate Symfony route in PrestaShop module"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/bb871a3e8dd81b2b0a1690f195da6208","name":"Vineet Kr. Gupta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b8dd0faa3589c82d64586b71a9e84be11a8b9a8f3b74bb952442b904af1c68f2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b8dd0faa3589c82d64586b71a9e84be11a8b9a8f3b74bb952442b904af1c68f2?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Vineet Kr. Gupta"},"description":"Proficient Software Engineer specializing in PrestaShop, with expertise in Mobile App Development, eCommerce Platform Development, and POS services. Delivers innovative, user-focused solutions that enhance functionality and drive efficient business operations.","url":"https:\/\/webkul.com\/blog\/author\/vineetkr-gupta008\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/369818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/386"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=369818"}],"version-history":[{"count":10,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/369818\/revisions"}],"predecessor-version":[{"id":370366,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/369818\/revisions\/370366"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=369818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=369818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=369818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}