Skip to content
Advertisement

Magento 2 Block template is working locally and doen’t on server

I’m new at Magento I created a new page to list some data that is coming from an API, and I used that a Block base on phtml template and I pass the data loaded from API to the block to list it. this code is working fine locally but when I deploy it to the server it crashes please help me.

here is my code

Constroller/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;
    }

View/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="MagentoBackendBlockTemplate" template="Company_CompanyShipping::pickuprequest.phtml"/>
        </referenceContainer>
    </body>
</page>

View/adminhtml/templates/pickuprequests.phtml

use MagentoFrameworkViewElementTemplate;

/** @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>

Advertisement

Answer

Hello guys i found the problem, When i’m using windows it causes no problem cause windows is not key sensitive on the other hand the server is a linux machine that is key sensitive so when i’m using View/adminhtml/templates/pickuprequests.phtml with capital V it doesn’t find the template called and it doesn’t trigger any error.

all i had to do is change View to view and everything worked so well.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement