【问题标题】:Magento 2 Block template is working locally and doen't on serverMagento 2 Block 模板在本地工作,不在服务器上
【发布时间】:2021-07-02 01:11:03
【问题描述】:

我是 Magento 的新手,我创建了一个新页面来列出来自 API 的一些数据,我使用了一个基于 phtml 模板的块,并将从 API 加载的数据传递给块以列出它。这段代码在本地运行良好,但是当我将它部署到服务器时它崩溃了,请帮助我。

这是我的代码

Controller/Adminhtml/PickupRequest/Index.php

public function execute()
    {
        $resultPage = $this->resultPageFactory->create();
        $resultPage->setActiveMenu(static::MENU_ID);
        $resultPage->getConfig()->getTitle()->prepend(__('Pickup Requests'));
        $data = array();
        $block = $resultPage->getLayout()->getBlock('pickup_request_listing');
        try {
            $sessionClient = $this->authService->authenticate();
            $data = $this->_pickupRequestClient->getPickupRequests($sessionClient);
            $block->setData('pickupRequests', $data);
            $resultPage->getLayout()->addBlock($block);
        } catch (\Exception $e) {
            $this->_logger->err($e->getMessage());
            $this->_logger->err($e->getTraceAsString());
        }
        return $resultPage;
    }

查看/adminhtml/layout/companyshipping_pickuprequest_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceBlock name="page.title">
        <action method="setPageTitle">
            <argument name="title" xsi:type="string">Demande de ramassage</argument>
        </action>
    </referenceBlock>
    <body>
        <referenceContainer name="content">
            <block name="pickup_request_listing" class="Magento\Backend\Block\Template" template="Company_CompanyShipping::pickuprequest.phtml"/>
        </referenceContainer>
    </body>
</page>

查看/adminhtml/templates/pickuprequests.phtml


use Magento\Framework\View\Element\Template;

/** @var Template $block */
?>
<?php
$count = 0;
$pickupRequests = $block->getData('pickupRequests');
?>
<div>
    <table class="data-grid data-grid-draggable">
        <thead>
        <tr>
            <th class="data-grid-th">Refrence</th>
            <th class="data-grid-th">Customer</th>
            <th class="data-grid-th">Package count</th>
            <th class="data-grid-th">Created On</th>
            <th class="data-grid-th">Picked up on</th>
            <th class="data-grid-th">Status</th>
        </tr>
        </thead>
        <tbody>
        <?php
        if (isset($pickupRequests) && $pickupRequests != null && count($pickupRequests) > 0) {
            foreach ($pickupRequests as $pickupRequest) { ?>
                <tr class="data-row <?= $count % 2 == 0 ? '_odd-row' : '' ?>">
                    <td>
                        <div class="data-grid-cell-content"><?= $pickupRequest["name"]; ?></div>
                    </td>
                    <td>
                        <div class="data-grid-cell-content"><?= $pickupRequest["customer"]; ?></div>
                    </td>
                    <td>
                        <div class="data-grid-cell-content"><?= $pickupRequest["count"]; ?></div>
                    </td>
                    <td>
                        <div
                            class="data-grid-cell-content"><?= date("d/m/Y", strtotime($pickupRequest["createdOn"])); ?></div>
                    </td>
                    <td>
                        <div
                            class="data-grid-cell-content"><?php
                            if (isset($pickupRequest["pickedUpAt"])) {
                                echo date("d/m/Y", strtotime($pickupRequest["pickedUpAt"]));
                            }
                            ?></div>
                    </td>
                    <td>
                        <button class="<?= getStatusClass($pickupRequest["status"]); ?>"><?= getStatusLabel($pickupRequest["status"]); ?></button>
                    </td>
                </tr>
                <?php $count++; ?>
            <?php }
        } else { ?>
            <tr class="data-row">
                <td colspan="100">Aucun résultat trouvé..</td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
</div>

【问题讨论】:

  • 它是如何在服务器上崩溃的?
  • 您可以先查看 var/log 或 var/report 文件夹以找出任何错误消息
  • 我检查过但没有问题
  • @L.C.EchoChan 我发现我在文件夹查看中使用大写的问题我所要做的就是将其更改为查看,它工作了谢谢

标签: php templates magento2 block


【解决方案1】:

大家好,我发现了问题, 当我使用 Windows 时,它不会导致任何问题,因为 Windows 对键不敏感,另一方面,服务器是对键敏感的 linux 机器 所以当我使用带有大写 V 的 View/adminhtml/templates/pickuprequests.phtml 时,它找不到调用的模板,也不会触发任何错误。

我所要做的就是将视图更改为视图,一切都运行良好。

【讨论】:

    猜你喜欢
    • 2016-05-17
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 2017-02-22
    相关资源
    最近更新 更多