在 Prestashop 1.5.3 中创建自定义页面 [英] Create custom page in Prestashop 1.5.3
问题描述
我想在不使用 CMS 的情况下在 Prestashop 1.5.3 中创建自定义页面.
I'd like to create a custom page in Prestashop 1.5.3 without using CMS.
很遗憾,我找不到任何适用于 1.5.3 的教程.
Unfortunately I can not find any tutorials that are working with 1.5.3.
到目前为止,我已经在商店根目录中创建了一个 test.php 文件,内容如下:
So far I have created a test.php file in the shops root directory with following content:
<?php
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');
$smarty->display(_PS_THEME_DIR_.'test.tpl');
?>
我将相应的 test.tpl 放在我的主题基础文件夹中.它只包含hello world".
I placed the corresponding test.tpl in my themes basefolder. It simply contains 'hello world'.
我更改了 blockmenu.php 并创建了一个指向我的页面的自定义链接:
I changed the blockmenu.php and created a custom link to my page:
$this->_menu .= '<li><a href="test.php">TEST</a></li>'.PHP_EOL;
如果我单击链接,页面会显示,但 html 已损坏.页面的 body-id 设置为 pagenotfound 并且生成左列但未显示.有没有办法为我的自定义页面设置 $page_name 以便我可以检查我的自定义页面是否已加载并抑制左右列的生成?
If I click the link the page is displayed but the html is some kind of corrupt. The body-id of the page is set to pagenotfound and the left column is generated but is not shown. Is there any way to set the $page_name for my custom page so that I can check if my custom page is loaded and to supress the generation of the left and right columns?
有没有其他方法可以在没有 CMS 的情况下创建功能性自定义页面?
Is there any other way to create a functional custom page without CMS?
推荐答案
只需使用您想要的页面名称创建一个控制器,并将其放在/overrides/controllers/front/中.控制器的名称必须是 NameyouwantforthepageController.php
Just create a controller with the name you want for the page, and put it in /overrides/controllers/front/. The name of the controller must be NameyouwantforthepageController.php
这是一个可以工作的基本类:
Here is a basic class that will work:
class MyPageController extends FrontController {
/**
* Initialize controller
* @see FrontController::init()
*/
public function init() {
parent::init();
}
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent() {
parent::initContent();
$this->setTemplate(_PS_THEME_DIR_.'my-page.tpl');
}
}
查看 FrontController 以了解您需要覆盖哪些方法来添加功能,例如 setMedia()
以添加 CSS/JS 文件.
Take a look at the FrontController to see what method you need to override to add functionnalities, for example setMedia()
to add CSS / JS files.
然后您就可以在后台的 SEO 面板中添加一个漂亮的网址.
You will then be able to add a pretty url in the back office in the SEO panel.
这篇关于在 Prestashop 1.5.3 中创建自定义页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!