{"id":310525,"date":"2021-10-29T15:28:40","date_gmt":"2021-10-29T15:28:40","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=310525"},"modified":"2022-04-29T10:09:13","modified_gmt":"2022-04-29T10:09:13","slug":"using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/","title":{"rendered":"Using classes in PrestaShop 1.7 Symfony controller"},"content":{"rendered":"\n<p>In blog <a href=\"https:\/\/webkul.com\/blog\/override-a-symfony-controller-in-prestashop-1-7\/\" target=\"_blank\" rel=\"noreferrer noopener\">Override a Symfony Controller<\/a> we discuss about overriding Symfony controllers available in PrestaShop.  Now suppose, we need to use<strong> classes <\/strong>in PrestaShop 1.7 Symfony controller, how we do that?<\/p>\n\n\n\n<p>In this blog, we are going to learn how to use&nbsp;methods and function define in PrestaShop core classes, module main class file or from module classes.<\/p>\n\n\n\n<p>There are following ways to use classes in overridden Symfony controllers :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Use Method<\/li><li>By Module Instance method<\/li><\/ul>\n\n\n\n<p>Let\u2019s understand the entire process to override with the help of taking an example as given below.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Use Method<\/h4>\n\n\n\n<p>Just add below lines at the top of the Symfony Controller say <code><strong>DemoController.php<\/strong><\/code> file after namespace to use PrestaShop classes.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">namespace Webkul\\Controller\\Admin;\n\nuse Configuration;\nuse ModuleName;\nuse Student;\n\nuse PrestaShopBundle\\Controller\\Admin\\FrameworkBundleAdminController;\nuse Symfony\\Component\\HttpFoundation\\Request;\n\nclass DemoController extends FrameworkBundleAdminController\n{\n     $objConf = new Configuration();\n&lt;strong&gt;                 or&lt;\/strong&gt;\n     $objMod = new ModuleName();\n&lt;strong&gt;                 or&lt;\/strong&gt;\n     $objStu = new Student();<\/pre>\n\n\n\n<p>Here, <br><code><strong>use Configuration;<\/strong><\/code>  loads core Configuration class.<br><code><strong>use ModuleName;<\/strong><\/code>  load module main class file.<br><strong><code>use  Student;<\/code><\/strong> load Student class inside module classes folder.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Module Instance Method<\/h4>\n\n\n\n<p>This method is only used to load module main class function. Load module instance in Symfony controller as below :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">$module = Module::getInstanceByName(&#039;modulename&#039;);\nif (method_exists($module, &#039;getNewFunction&#039;)) {\n    $result = $module-&gt;getNewFunction();\n}<\/pre>\n\n\n\n<p>In this example we load module main class file and it&#8217;s method <strong><code>getNewFunction()<\/code><\/strong> by creating module instance.<\/p>\n\n\n\n<p>We can also implement use classes in PrestaShop 1.7 Symfony controller if we need to load method from other modules.<\/p>\n\n\n\n<p>This is how we can use the classes in Symfony Controller in our 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 blog Override a Symfony Controller we discuss about overriding Symfony controllers available in PrestaShop. Now suppose, we need to use classes in PrestaShop 1.7 Symfony controller, how we do that? In this blog, we are going to learn how to use&nbsp;methods and function define in PrestaShop core classes, module main class file or from <a href=\"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/\">[&#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":[4126,2710],"class_list":["post-310525","post","type-post","status-publish","format-standard","hentry","category-prestashop","tag-prestashop-1-7","tag-symfony"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using classes in PrestaShop 1.7 Symfony controller - Webkul Blog<\/title>\n<meta name=\"description\" content=\"How to use core, module main file and module classes methods in overridden Symfony controller in PrestaShop 1.7, while creating a new module.\" \/>\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\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using classes in PrestaShop 1.7 Symfony controller - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"How to use core, module main file and module classes methods in overridden Symfony controller in PrestaShop 1.7, while creating a new module.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/\" \/>\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=\"2021-10-29T15:28:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-29T10:09:13+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\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/\"},\"author\":{\"name\":\"Vineet Kr. Gupta\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/bb871a3e8dd81b2b0a1690f195da6208\"},\"headline\":\"Using classes in PrestaShop 1.7 Symfony controller\",\"datePublished\":\"2021-10-29T15:28:40+00:00\",\"dateModified\":\"2022-04-29T10:09:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/\"},\"wordCount\":268,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"Prestashop 1.7\",\"symfony\"],\"articleSection\":[\"prestashop\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/\",\"url\":\"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/\",\"name\":\"Using classes in PrestaShop 1.7 Symfony controller - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2021-10-29T15:28:40+00:00\",\"dateModified\":\"2022-04-29T10:09:13+00:00\",\"description\":\"How to use core, module main file and module classes methods in overridden Symfony controller in PrestaShop 1.7, while creating a new module.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using classes in PrestaShop 1.7 Symfony controller\"}]},{\"@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":"Using classes in PrestaShop 1.7 Symfony controller - Webkul Blog","description":"How to use core, module main file and module classes methods in overridden Symfony controller in PrestaShop 1.7, while creating a new module.","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\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/","og_locale":"en_US","og_type":"article","og_title":"Using classes in PrestaShop 1.7 Symfony controller - Webkul Blog","og_description":"How to use core, module main file and module classes methods in overridden Symfony controller in PrestaShop 1.7, while creating a new module.","og_url":"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2021-10-29T15:28:40+00:00","article_modified_time":"2022-04-29T10:09:13+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\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/"},"author":{"name":"Vineet Kr. Gupta","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/bb871a3e8dd81b2b0a1690f195da6208"},"headline":"Using classes in PrestaShop 1.7 Symfony controller","datePublished":"2021-10-29T15:28:40+00:00","dateModified":"2022-04-29T10:09:13+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/"},"wordCount":268,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["Prestashop 1.7","symfony"],"articleSection":["prestashop"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/","url":"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/","name":"Using classes in PrestaShop 1.7 Symfony controller - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2021-10-29T15:28:40+00:00","dateModified":"2022-04-29T10:09:13+00:00","description":"How to use core, module main file and module classes methods in overridden Symfony controller in PrestaShop 1.7, while creating a new module.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/using-core-or-module-classes-in-prestashop-1-7-overriden-symfony-controller\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Using classes in PrestaShop 1.7 Symfony controller"}]},{"@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\/310525","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=310525"}],"version-history":[{"count":20,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/310525\/revisions"}],"predecessor-version":[{"id":332003,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/310525\/revisions\/332003"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=310525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=310525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=310525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}