{"id":1069,"date":"2021-10-22T15:19:30","date_gmt":"2021-10-22T12:19:30","guid":{"rendered":"https:\/\/presta.site\/blog\/jak-utworzyc-nowa-strone-za-pomoca-kontrolera-frontowego-modulu\/"},"modified":"2026-06-30T09:12:28","modified_gmt":"2026-06-30T06:12:28","slug":"jak-utworzyc-nowa-strone-za-pomoca-kontrolera-frontowego-modulu","status":"publish","type":"post","link":"https:\/\/presta.site\/blog\/pl\/jak-utworzyc-nowa-strone-za-pomoca-kontrolera-frontowego-modulu\/","title":{"rendered":"Jak utworzy\u0107 now\u0105 stron\u0119 za pomoc\u0105 kontrolera frontowego modu\u0142u"},"content":{"rendered":"<p>Wi\u0119c chcesz utworzy\u0107 now\u0105 stron\u0119. To naprawd\u0119 proste, wystarczy napisa\u0107 kilka linii kodu.<\/p>\n<p>Ten samouczek dotyczy <strong>PrestaShop 1.6<\/strong>. Inne wersje s\u0105 podobne, ale mog\u0105 si\u0119 nieznacznie r\u00f3\u017cni\u0107.<\/p>\n<p><!--more--><\/p>\n<p>Za\u0142\u00f3\u017cmy, \u017ce chcemy utworzy\u0107 kontroler &#8220;<strong>Test<\/strong>&#8221; dla modu\u0142u &#8220;<strong>MyModule<\/strong>&#8220;. Zmie\u0144 &#8220;Test&#8221; i &#8220;MyModule&#8221; na swoje rzeczywiste warto\u015bci.<\/p>\n<ol>\n<li>Najpierw musisz przej\u015b\u0107 do katalogu swojego modu\u0142u.<\/li>\n<li>Utw\u00f3rz tam nowy katalog &#8220;<strong>controllers<\/strong>&#8220;. A wewn\u0105trz niego utw\u00f3rz katalog &#8220;<strong>front<\/strong>&#8220;.<br \/>\nWi\u0119c struktura plik\u00f3w powinna wygl\u0105da\u0107 tak: &#8220;mymodule\/controllers\/front\/&#8221;<\/li>\n<li>W tym katalogu &#8220;front&#8221; utw\u00f3rz nowy plik PHP: <strong>test.php<\/strong><\/li>\n<li>Wklej nast\u0119puj\u0105cy kod do tego pliku:\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>Jak wida\u0107, klasa kontrolera rozszerza ModuleFrontController i powinna nazywa\u0107 si\u0119 &lt;<strong>nazwa_modu\u0142u<\/strong>&gt;&lt;<strong>nazwa_kontrolera<\/strong>&gt;ModuleFrontController.<\/li>\n<\/ol>\n<p><strong>Gotowe!<\/strong><\/p>\n<p>Mo\u017cesz zobaczy\u0107 swoj\u0105 now\u0105 stron\u0119 pod nast\u0119puj\u0105cym adresem URL:<br \/>\n<strong>twoja_strona<\/strong>\/index.php?fc=module&amp;module=<strong>mymodule<\/strong>&amp;controller=<strong>test<\/strong><br \/>\nLUB<br \/>\n<strong>twoja_strona<\/strong>\/module\/<strong>mymodule<\/strong>\/<strong>test<\/strong><br \/>\nPrzejd\u017a do swojego back office do zak\u0142adki Preferencje &gt; SEO i URL. Tam mo\u017cesz klikn\u0105\u0107 &#8220;<strong>Dodaj now\u0105 stron\u0119<\/strong>&#8221; i ustawi\u0107 niestandardowy przyjazny adres URL dla swojej strony.<\/p>\n<h3>Teraz mo\u017cesz dostosowa\u0107 now\u0105 stron\u0119<\/h3>\n<p>Na przyk\u0142ad u\u017cyj zmiennej <strong>display_column_left<\/strong>, aby kontrolowa\u0107 wy\u015bwietlanie lewej kolumny.<\/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>Dodajmy troch\u0119 tre\u015bci do nowej strony<\/h3>\n<p>Utw\u00f3rz nowy plik szablonu: &#8220;mymodule<strong>\/views\/templates\/front\/test.tpl<\/strong>&#8221; i umie\u015b\u0107 tam troch\u0119 tekstu.<br \/>\nU\u017cyj tego szablonu:<\/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>Wi\u0119c chcesz utworzy\u0107 now\u0105 stron\u0119. To naprawd\u0119 proste, wystarczy napisa\u0107 kilka linii kodu. Ten samouczek dotyczy PrestaShop 1.6. Inne wersje s\u0105 podobne, ale mog\u0105 si\u0119 nieznacznie r\u00f3\u017cni\u0107.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[149],"tags":[],"class_list":["post-1069","post","type-post","status-publish","format-standard","hentry","category-rozwoj"],"_links":{"self":[{"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/posts\/1069","targetHints":{"allow":["GET"]}}],"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=1069"}],"version-history":[{"count":0,"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/posts\/1069\/revisions"}],"wp:attachment":[{"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/media?parent=1069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/categories?post=1069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/presta.site\/blog\/wp-json\/wp\/v2\/tags?post=1069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}