Prestashop:如何在renderView()中加载.tpl文件

时间:2014-09-08 12:40:21

标签: php prestashop

我在我开发的prestashop模块上加载自定义tpl文件时遇到问题。一般代码是这个

class AdminManageShipmentsController extends ModuleAdminController{

public function __construct()
{
    $this->bootstrap = true;
    $this->table = 'order';
    $this->className = 'Order';
    $this->addRowAction('view');
    $this->lang = false;

    $this->explicitSelect = true;
    $this->allow_export = true;
    $this->deleted = false;
    $this->context = Context::getContext();

    $this->_select = '
    a.id_currency,
    a.id_order AS id_pdf,
    a.date_add,
    CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
    osl.`name` AS `osname`,
    os.`color`,
    IF((SELECT COUNT(so.id_order) FROM `'._DB_PREFIX_.'orders` so
     WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new,
    country_lang.name as cname,
    IF(a.valid, 1, 0) badge_success';

    $this->_join = '
    INNER JOIN `'._DB_PREFIX_.'carrier` ca ON (a.id_carrier=ca.id_carrier)
    LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`)
    INNER JOIN `'._DB_PREFIX_.'address` address ON address.id_address = a.id_address_delivery
    INNER JOIN `'._DB_PREFIX_.'country` country ON address.id_country = country.id_country
    INNER JOIN `'._DB_PREFIX_.'country_lang` country_lang ON (country.`id_country` = country_lang.`id_country` AND country_lang.`id_lang` = '.(int)$this->context->language->id.')
    LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = a.`current_state`)
    LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->context->language->id.')';
    $this->_orderBy = 'id_order';
    $this->_orderWay = 'DESC';

    $statuses = OrderState::getOrderStates((int)$this->context->language->id);
    foreach ($statuses as $status)
        $this->statuses_array[$status['id_order_state']] = $status['name'];

    $this->fields_list = array(
        'id_order' => array(
            'title' => $this->l('ID'),
            'align' => 'text-center',
            'class' => 'fixed-width-xs'
        ),
        'date_add' => array(
            'title' => $this->l('Purchased on')
        ),
        'customer' => array(
            'title' => $this->l('Customer'),
            'havingFilter' => true,
        ),
        'osname' => array(
            'title' => $this->l('Status'),
            'type' => 'select',
            'color' => 'color',
            'list' => $this->statuses_array,
            'filter_key' => 'os!id_order_state',
            'filter_type' => 'int',
            'order_key' => 'osname'
        ),
    );

    parent::__construct();
}

public function renderView()
{
    return parent::renderView();
}

}

此类用于显示特定运营商的订单。每个订单旁边都有一个查看按钮,当您按下它时,它必须显示自定义tpl文件。

问题是我找不到为什么不显示。我把文件放在这个位置

/模块/ MyModule的/视图/模板/管理/ MyModule的/助手/视图/

但没有任何事情只是空白页面。如果我只是输入以返回简单的html或文本,它会显示出来。

有人知道为什么会这样吗?

1 个答案:

答案 0 :(得分:0)

将这一行添加到您的构造函数中:

$this->module = 'MyModuleName';

其中MyModuleName是您的模块名称(显然):)。


然后在你的renderView方法中:

if(!($myobject = $this->loadObject()))
    return;

// Get other data from object
$order = new Order($myobject->id_order);

// Set your tpl vars
$this->tpl_view_vars = array([...]);

return parent:renderView();

然后将view.tpl放在此路径中:

/modules/mymodule/views/templates/admin/manage_shipments/view/view.tpl

在view.tpl文件中:

{extends file="helpers/view/view.tpl"}
{block name="override_tpl"}
/* Your code to view information */
{/block}