如何在prestashop的自定义模块中从我的管理控制器加载模板文件

如何在prestashop的自定义模块中从我的管理控制器加载模板文件,prestashop,prestashop-1.6,Prestashop,Prestashop 1.6,如何在prestashop 1.6的自定义模块中从我的管理控制器加载模板文件 if (!defined('_PS_VERSION_')) exit; class QueryAllTrxController extends ModuleAdminController { public $module; public function __construct() { parent::__construct(); } public function initContent() { parent:

如何在prestashop 1.6的自定义模块中从我的管理控制器加载模板文件

if (!defined('_PS_VERSION_')) exit;
 class QueryAllTrxController extends ModuleAdminController
{

public $module;
public function __construct()
{
parent::__construct();
}

public function initContent()
{
parent::initContent();
$this->setTemplate('display.tpl');
//$this->setTemplate(_PS_THEME_DIR_.'mypage.tpl');
}    

}

代码
$this->setTemplate('display.tpl')
正在加载模板文件
modules/your custom module/views/templates/admin/display.tpl
modules/your custom module/display.tpl
代码
$this->setTemplate('display.tpl')
正在加载一个模板文件
模块/您的自定义模块/视图/模板/管理员/显示.tpl
模块/您的自定义模块/显示.tpl

必须这样命名类名:AdminQueryAllTrxController

您可以将display.tpl放入:

modules\module_name\views\templates\admin\classe_name(QueryAllTrx)

并使用:
$this->setTemplate('display.tpl')
在AdminQueryAllTrxController中

必须按以下方式命名类名:AdminQueryAllTrxController

您可以将display.tpl放入:

modules\module_name\views\templates\admin\classe_name(QueryAllTrx)

并使用:
$this->setTemplate('display.tpl')在您的AdminQueryAllTrxController中

我遇到了同样的问题,并且花了很长时间才解决。 我最终在这段视频中找到了解决方案:

我就是这样让它工作的:

1-在ModuleName/controllers/AdminMyControllerNameController.php中创建控制器

class AdminMyControllerNameController extends ModuleAdminController
{

public function __construct()
{
    $this->display = 'view';
    $this->meta_title = $this->l('metatitle');
    $this->toolbar_title = $this->l('tollbartitle');
    parent::__construct();
}

public function initContent()
{
    $this->show_toolbar = true;
    $this->display = 'view';
    $this->meta_title = $this->l('META TITLE');

    parent::initContent();

    $this->setTemplate('templatename.tpl');


}

public function initToolBarTitle()
{
    $this->toolbar_title = $this->l('TOOLBAR TITLE??');
}

public function initToolBar()
{
    return true;
}

}
2-在ModuleName/views/admin/my\u controller\u name/template.tpl中创建模板文件

您必须在views/admin文件夹中创建一个目录,使用用snake-case编写的控制器名称


无论如何,我希望这会有所帮助。

我也有同样的问题,我花了很长时间才解决。 我最终在这段视频中找到了解决方案:

我就是这样让它工作的:

1-在ModuleName/controllers/AdminMyControllerNameController.php中创建控制器

class AdminMyControllerNameController extends ModuleAdminController
{

public function __construct()
{
    $this->display = 'view';
    $this->meta_title = $this->l('metatitle');
    $this->toolbar_title = $this->l('tollbartitle');
    parent::__construct();
}

public function initContent()
{
    $this->show_toolbar = true;
    $this->display = 'view';
    $this->meta_title = $this->l('META TITLE');

    parent::initContent();

    $this->setTemplate('templatename.tpl');


}

public function initToolBarTitle()
{
    $this->toolbar_title = $this->l('TOOLBAR TITLE??');
}

public function initToolBar()
{
    return true;
}

}
2-在ModuleName/views/admin/my\u controller\u name/template.tpl中创建模板文件

您必须在views/admin文件夹中创建一个目录,使用用snake-case编写的控制器名称


无论如何,我希望这会有所帮助。

首先,将控制器添加到您的模块:

modules\module_name\controllers\admin\SomeNameController.php
通过ModuledMinController对其进行扩展,您需要至少两种方法才能使其正常工作\uuuu构造和初始化内容 将以下代码放在后面的方法中:

$this->content .= $this->context->smarty->fetch($this->pathToTpl);

            $this->context->smarty->assign(array(
                'content' => $this->content,
            ));
您可以用指向tpl文件的任何路径替换$this->pathtopl,我更喜欢动态创建路径。您可以在这里看到一个简单的示例:

class SomeNameController extends ModuleAdminController{
  var $pathToTpl;
  public function __construct()
    {
        $this->bootstrap = true;
        $this->context = Context::getContext();

        $this->pathToTpl = _PS_MODULE_DIR_ .
            $this->module->name .  // put the name of module
            '/views/templates/admin' .
            '/' .
            'templateName.tpl';
        parent::__construct();
    }

  public function initContent()
    {
        parent::initContent();

        $this->content .= $this->context->smarty->fetch($this->pathToTpl);

        $this->context->smarty->assign(array(
            'content' => $this->content,
        ));

    }

}
最后,您需要将templateName.tpl放在您想要的路径中:

modules\module_name\views\templates\admin\templateName.tpl

首先,将控制器添加到模块中:

modules\module_name\controllers\admin\SomeNameController.php
通过ModuledMinController对其进行扩展,您需要至少两种方法才能使其正常工作\uuuu构造和初始化内容 将以下代码放在后面的方法中:

$this->content .= $this->context->smarty->fetch($this->pathToTpl);

            $this->context->smarty->assign(array(
                'content' => $this->content,
            ));
您可以用指向tpl文件的任何路径替换$this->pathtopl,我更喜欢动态创建路径。您可以在这里看到一个简单的示例:

class SomeNameController extends ModuleAdminController{
  var $pathToTpl;
  public function __construct()
    {
        $this->bootstrap = true;
        $this->context = Context::getContext();

        $this->pathToTpl = _PS_MODULE_DIR_ .
            $this->module->name .  // put the name of module
            '/views/templates/admin' .
            '/' .
            'templateName.tpl';
        parent::__construct();
    }

  public function initContent()
    {
        parent::initContent();

        $this->content .= $this->context->smarty->fetch($this->pathToTpl);

        $this->context->smarty->assign(array(
            'content' => $this->content,
        ));

    }

}
最后,您需要将templateName.tpl放在您想要的路径中:

modules\module_name\views\templates\admin\templateName.tpl
这里的工作代码 背景:

您想添加带有自定义模块控制器的自定义管理员页面。但您无法自定义模板,因为您遇到以下错误消息:

致命错误:未捕获-->Smarty:无法加载模板文件“/var/www/html/admin dev/themes/default/template/catalog/index.tpl”module->name./views/templates/admin/”.$tpl_name)&&&&$this->viewAccess(){ //回显以下行并退出 返回$this->context->smarty->createTemplate($PS\u-THEME\u-DIR'modules/.$this->module->name./views/templates/admin/.$tpl\u-name,$this->context->smarty); }elseif(文件存在($this->getTemplatePath()。$this->override_folder.$tpl_name)&&&$this->viewAccess()){ //回显以下行并退出 返回$this->context->smarty->createTemplate($this->getTemplatePath()。$this->override_folder.$tpl_name,$this->context->smarty); } //发生此错误的原因是php访问以下行: 返回parent::createTemplate($tpl_name); }
照我说的做,你就能得到正确的文件路径。确保路径中存在该文件

我的PrestaShop版本是1.6.1.24

这里的工作代码 背景:

您想添加带有自定义模块控制器的自定义管理员页面。但您无法自定义模板,因为您遇到以下错误消息:

致命错误:未捕获-->Smarty:无法加载模板文件“/var/www/html/admin dev/themes/default/template/catalog/index.tpl”module->name./views/templates/admin/”.$tpl_name)&&&&$this->viewAccess(){ //回显以下行并退出 返回$this->context->smarty->createTemplate($PS\u-THEME\u-DIR'modules/.$this->module->name./views/templates/admin/.$tpl\u-name,$this->context->smarty); }elseif(文件存在($this->getTemplatePath()。$this->override_folder.$tpl_name)&&&$this->viewAccess()){ //回显以下行并退出 返回$this->context->smarty->createTemplate($this->getTemplatePath()。$this->override_folder.$tpl_name,$this->context->smarty); } //发生此错误的原因是php访问以下行: 返回parent::createTemplate($tpl_name); } 照我说的做,你就能得到正确的文件路径。确保路径中存在该文件


我的PrestaShop版本是1.6.1.24

在分配smarty变量后不应该调用fetch吗?在分配smarty变量后不应该调用fetch吗?