php OpenCart|视图未正确显示

2g32fytz  于 2023-09-29  发布在  PHP
关注(0)|答案(1)|浏览(114)

我是OpenCart的新手。我在管理面板中添加新的菜单称为价格经理。当我点击价格经理链接,我得到空页链接一样,我附上了截图。它不会沿着在管理面板中。
我怀疑是控制器的名字。
先谢了。

菜单

// Price Manager
        $data['menus'][] = [
            'id'       => 'menu-pricemanager',
            'icon'     => 'fas fa-home',
            'name'     => 'price_manager',
            'href'     => $this->url->link('catalog/price_manager', 'user_token=' . $this->session->data['user_token']),
            'children' => []
        ];

**控制器:**文件位置:controller/catalog/price_manager.php

<?php

namespace Opencart\Admin\Controller\Catalog;

class PriceManager extends \Opencart\System\Engine\Controller
{

public function index()
{
    $this->load->language('catalog/price_manager');

    $this->document->setTitle($this->language->get('heading_title'));

    $this->load->model('catalog/product');

    if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
        $discountPercentage = (float) $this->request->post['discount_percentage'] / 100;

        $products = $this->model_catalog_product->getProducts();

        foreach ($products as $product) {
            $price = $product['price'];
            $newPrice = $price - ($price * $discountPercentage);

            // $this->model_catalog_product->editProduct($product['product_id'], [
            //     'special' => $newPrice // Set special price as the discounted price
            // ]);
        }

        $this->session->data['success'] = $this->language->get('text_success');
        $this->response->redirect($this->url->link('catalog/price_manager', 'user_token=' . $this->session->data['user_token'], true));
    }

    $data['heading_title'] = $this->language->get('heading_title');

    $data['text_discount_percentage'] = $this->language->get('text_discount_percentage');
    $data['button_apply_discount'] = $this->language->get('button_apply_discount');

    $data['breadcrumbs'] = array();

    $data['breadcrumbs'][] = array(
        'text'      => $this->language->get('text_home'),
        'href'      => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true),
        'separator' => false
    );

    $data['breadcrumbs'][] = array(
        'text'      => $this->language->get('heading_title'),
        'href'      => $this->url->link('catalog/price_manager', 'user_token=' . $this->session->data['user_token'], true),
        'separator' => ' :: '
    );

    $data['action'] = $this->url->link('catalog/price_manager', 'user_token=' . $this->session->data['user_token'], true);

    $data['cancel'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);

    $this->response->setOutput($this->load->view('catalog/price_manager', $data));
}

protected function validate()
{
    if (!$this->user->hasPermission('modify', 'catalog/price_manager')) {
        $this->error['warning'] = $this->language->get('error_permission');
    }

    return !$this->error;
}
}

查看文件位置:view/template/catalog/price_manager.php

{{ header }}
{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
        <div class="pull-right">
            <button type="submit" form="form-price-manager" class="btn btn-primary">{{ button_apply_discount }}</button>
        </div>
        <h1>{{ heading_title }}</h1>
    </div>
</div>
<div class="container-fluid">
    <div class="panel panel-default">
        <div class="panel-body">
            <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-price-manager" class="form-horizontal">
                <div class="form-group">
                    <label class="col-sm-2 control-label">{{ text_discount_percentage }}</label>
                    <div class="col-sm-10">
                        <input type="text" name="discount_percentage" value="" class="form-control" />
                    </div>
                </div>
            </form>
        </div>
    </div>
   </div>
  </div>
{{ footer }}

截图:

0mkxixxg

0mkxixxg1#

您需要在index函数中添加headerfootercolumn_left变量。
下面是要添加到index函数中的实际代码

$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');

相关问题