{"id":314,"date":"2016-11-21T11:33:36","date_gmt":"2016-11-21T08:33:36","guid":{"rendered":"http:\/\/presta.site\/blog\/?p=314"},"modified":"2021-10-22T15:19:30","modified_gmt":"2021-10-22T12:19:30","slug":"how-to-create-a-new-page-using-module-front-controller","status":"publish","type":"post","link":"https:\/\/presta.site\/blog\/en\/how-to-create-a-new-page-using-module-front-controller\/","title":{"rendered":"How to create a new page using module front controller"},"content":{"rendered":"<p>So you want to create a new page. It&#8217;s really easy, you just need to write a few lines of code.<\/p>\n<p>This tutorial is for <strong>PrestaShop 1.6<\/strong>. Other versions are similar but can slightly differ.<\/p>\n<p><!--more--><\/p>\n<p>Let&#8217;s say we want to create a &#171;<strong>Test<\/strong>&#187; controller for a module &#171;<strong>MyModule<\/strong>&#171;. Change &#171;Test&#187; and &#171;MyModule&#187; to your actual values.<\/p>\n<ol>\n<li>First you need to navigate to your module&#8217;s directory.<\/li>\n<li>Create there a new directory &#171;<strong>controllers<\/strong>&#171;. And inside it create a directory &#171;<strong>front<\/strong>&#171;.<br \/>\nSo the file structure should be &#171;mymodule\/controllers\/front\/&#187;<\/li>\n<li>In that &#171;front&#187; directory create a new PHP file: <strong>test.php<\/strong><\/li>\n<li>Paste the following code into that file:\n<div class=\"codecolorer-container php blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/><\/div><\/td><td><div class=\"php codecolorer\"><span class=\"kw2\">class<\/span> MyModuleTestModuleFrontController <span class=\"kw2\">extends<\/span> ModuleFrontController<br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>As you can see, controller&#8217;s class extends ModuleFrontController and should be called like &lt;<strong>module_name<\/strong>&gt;&lt;<strong>controller_name<\/strong>&gt;ModuleFrontController.<\/li>\n<\/ol>\n<p><strong>All done!<\/strong><\/p>\n<p>You can view your new page by the following url:<br \/>\n<strong>your_site<\/strong>\/index.php?fc=module&amp;module=<strong>mymodule<\/strong>&amp;controller=<strong>test<\/strong><br \/>\nOR<br \/>\n<strong>your_site<\/strong>\/module\/<strong>mymodule<\/strong>\/<strong>test<\/strong><br \/>\nGo to your Back Office to the tab Preferences &gt; SEO &amp; URLs. There you can click &#171;<strong>Add a new page<\/strong>&#187; and set a custom friendly url for your page.<\/p>\n<h3>Now, you can customize the new page<\/h3>\n<p>For example, use the <strong>display_column_left<\/strong> variable to control left column displaying.<\/p>\n<div class=\"codecolorer-container php blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/><\/div><\/td><td><div class=\"php codecolorer\"><span class=\"kw2\">class<\/span> MyModuleTestModuleFrontController <span class=\"kw2\">extends<\/span> ModuleFrontController<br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">public<\/span> <span class=\"re0\">$display_column_left<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw4\">false<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<h3>Let&#8217;s add some content to the new page<\/h3>\n<p>Create a new template file: &#171;mymodule<strong>\/views\/templates\/front\/test.tpl<\/strong>&#187; and place there some text.<br \/>\nUse that template:<\/p>\n<div class=\"codecolorer-container php blackboard\" style=\"overflow:auto;white-space:nowrap;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/><\/div><\/td><td><div class=\"php codecolorer\"><span class=\"kw2\">class<\/span> MyModuleTestModuleFrontController <span class=\"kw2\">extends<\/span> ModuleFrontController<br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">public<\/span> <span class=\"kw2\">function<\/span> initContent<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; parent<span class=\"sy0\">::<\/span><span class=\"me2\">initContent<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"re0\">$this<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">setTemplate<\/span><span class=\"br0\">&#40;<\/span><span class=\"st_h\">'test.tpl'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n","protected":false},"excerpt":{"rendered":"<p>So you want to create a new page. It&#8217;s really easy, you just need to write a few lines of code. This tutorial is for PrestaShop 1.6. Other versions are similar but can slightly differ.<\/p>\n","protected":false},"author":1,"featured_media":341,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[25,1],"tags":[],"_links":{"self":[{"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/posts\/314"}],"collection":[{"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/comments?post=314"}],"version-history":[{"count":36,"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/posts\/314\/revisions"}],"predecessor-version":[{"id":362,"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/posts\/314\/revisions\/362"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/media\/341"}],"wp:attachment":[{"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/media?parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/categories?post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/tags?post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}