我是 Opencart 的新手,我正在尝试实现一个自定义模块。我可以将它们添加到扩展中https://prnt.sc/3zYnLR3_bqM6。在主页布局中添加了以下模块以查看其是否正常工作https://prnt.sc/UNx6dtTc7p9L。目前它没有显示自定义部分。
我尝试重新检查代码,不知道它是否正确,因为我遵循了在 YT 和打开购物车相关论坛中看到的大多数教程。使用解决方法仍然不成功。想知道如何让它出现在网站上。
这是我的代码,以防万一:
管理员>>控制器:
<?php
class ControllerExtensionModuleTestSection extends Controller {
public function index() {
// Do note that below are the sample for using module helper, you may use it in other modules
$array = array(
'oc' => $this,
'heading_title' => 'Test Section',
'modulename' => 'test_section',
'fields' => array(
array('type' => 'text', 'label' => 'Title', 'name' => 'title'),
array('type' => 'textarea', 'label' => 'First Section Description', 'name' => 'first_section_description','ckeditor'=>true),
array('type' => 'repeater', 'label' => 'First Section Logos', 'name' => 'first_section_logos',
'fields' => array(
array('type' => 'image', 'label' => 'Logos', 'name' => 'image'),
)),
array('type' => 'text', 'label' => 'Second Section Title', 'name' => 'second_section_title'),
array('type' => 'textarea', 'label' => 'Second Section Description 1', 'name' => 'second_section_description_1','ckeditor'=>true),
array('type' => 'repeater', 'label' => 'Second Section Logos', 'name' => 'second_section_logos',
'fields' => array(
array('type' => 'image', 'label' => 'Logos', 'name' => 'image'),
array('type' => 'text', 'label' => 'Title', 'name' => 'title'),
)),
array('type' => 'textarea', 'label' => 'Second Section Description 2', 'name' => 'second_section_description_2','ckeditor'=>true),
array('type' => 'image', 'label' => 'Third Section Vision Image', 'name' => 'third_section_vision_image'),
array('type' => 'text', 'label' => 'Third Section Vision Title', 'name' => 'third_section_vision_title'),
array('type' => 'textarea', 'label' => 'Third Section Vision Statement', 'name' => 'third_section_vision_statement','ckeditor'=>true),
array('type' => 'image', 'label' => 'Third Section Mission Image', 'name' => 'third_section_mission_image'),
array('type' => 'text', 'label' => 'Third Section Mission Title', 'name' => 'third_section_mission_title'),
array('type' => 'textarea', 'label' => 'Third Section Mission Statement', 'name' => 'third_section_mission_statement','ckeditor'=>true),
array('type' => 'text', 'label' => 'Third Section Value Statement Title', 'name' => 'third_section_value_statement_title'),
array('type' => 'repeater', 'label' => 'Third Section Logos', 'name' => 'third_section_logos',
'fields' => array(
array('type' => 'image', 'label' => 'Logos', 'name' => 'image'),
array('type' => 'textarea', 'label' => 'Description', 'name' => 'description','ckeditor'=>true),
)),
array('type' => 'text', 'label' => 'Fourth Section Title', 'name' => 'fourth_section_title'),
array('type' => 'textarea', 'label' => 'Fourth Section Description', 'name' => 'fourth_section_description','ckeditor'=>true),
array('type' => 'repeater', 'label' => 'Fourth Section Logos', 'name' => 'fourth_section_logos',
'fields' => array(
array('type' => 'image', 'label' => 'Logos', 'name' => 'image'),
array('type' => 'textarea', 'label' => 'Description', 'name' => 'description','ckeditor'=>true),
)),
),
);
$this->modulehelper->init($array);
}
}
目录>>控制器:
<?php
class ControllerExtensionModuleTestSection extends Controller {
public function index($setting) {
$oc = $this;
$language_id = $this->config->get('config_language_id');
$modulename = 'test_section';
$this->load->library('modulehelper');
$Modulehelper = Modulehelper::get_instance($this->registry);
$data = array(
'title' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'title' ),
'first_section_description' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'first_section_description' ),
'first_section_logos' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'first_section_logos' ),
'second_section_title' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'second_section_title' ),
'second_section_description_1' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'second_section_description_1' ),
'second_section_logos' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'second_section_logos' ),
'second_section_description_2' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'second_section_description_2' ),
'third_section_vision_title' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'third_section_vision_title' ),
'third_section_vision_image' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'third_section_vision_image' ),
'third_section_vision_statement' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'third_section_vision_statement' ),
'third_section_mission_title' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'third_section_mission_title' ),
'third_section_mission_image' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'third_section_mission_image' ),
'third_section_mission_statement' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'third_section_mission_statement' ),
'third_section_value_statement_title' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'third_section_value_statement_title' ),
'third_section_logos' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'third_section_logos' ),
'fourth_section_title' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'fourth_section_title' ),
'fourth_section_description' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'fourth_section_description' ),
'fourth_section_logos' => $Modulehelper->get_field ( $oc, $modulename, $language_id, 'fourth_section_logos' ),
);
return $this->load->view('extension/module/test_section', $data);
}
}
en_gb 语言:
<?php
// Heading
$_['heading_title'] = 'Test Section';
$_['text_module'] = 'Modules';
$_['text_extension'] = 'Extension';
$_['text_success'] = 'Success: You have modified Test Section module!';
$_['text_edit'] = 'Edit Test Section Module';
模型视图:
<style>
.hex-mobile-only {
display: none;
}
@media(max-width:1023px) {
.hex-mobile-only {
display: block;
}
.hex-mobile-container {
display: flex;
width: 100%;
flex-wrap: wrap;
}
.hex-mobile-wrap {
width: calc((100%/3) - 20px);
height: auto;
margin-left: 20px;
}
.hex-mobile-wrap img {
width:100%
}
.hex-mobile-container .hex-mobile-wrap p {
font-weight: 600;
padding: 20px 0;
text-align: center;
}
}
@media(max-width: 767px) {
.hex-mobile-container {
display: flex;
width: 80%;
flex-direction: column;
margin: 0 auto;
}
.hex-mobile-wrap {
width:100%;
height: auto;
margin-left: 0px;
}
.hex-mobile-wrap img {
width:100%;
height: auto;
}
}
img.hex-img {
width: 110%;
height: auto;
display: block;
object-fit: cover;
transform: rotate(90deg);
position: absolute;
top: 18px;
right: -11px
}
p.hex-title {
position: absolute;
transform: rotate(90deg);
z-index: 99;
font-weight: 600;
color: #000066 !important;
}
.hexagon-gallery {
margin: auto;
/*margin-top: 10px;*/
max-width: 1000px;
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-auto-rows: 200px;
grid-gap: 0px;
padding-left: 50px;
transform: rotate(270deg);
}
@media(max-width: 1024px) {
.hexagon-gallery { margin: auto;
margin-top: 80px;
max-width: 1000px;
display: grid;
grid-template-columns: repeat(6, 1fr);
grid-auto-rows: 200px;
grid-gap: 0px;
padding-left: 50px;
transform: rotate(270deg);
}
p.hex-title {
width: 250px;
}
}
@media(max-width:1023px) {
.hexagon-gallery {
display: none;
}
}
.clip-path {
display: flex;
position: relative;
width: 220px;
height: 245px;
background-color: #424242;
/*-webkit-clip-path: polygon(*/
/* 50% 0%,*/
/* 100% 25%,*/
/* 100% 75%,*/
/* 50% 100%,*/
/* 0% 75%,*/
/* 0% 25%*/
/*);*/
/*clip-path: polygon(*/
/* 50% 0%,*/
/* 100% 25%,*/
/* 100% 75%,*/
/* 50% 100%,*/
/* 0% 75%,*/
/* 0% 25%*/
/*);*/
-webkit-clip-path: polygon( 50% 1%, 97% 25%, 97% 75%, 50% 99%, 3% 75%, 3% 25% );
clip-path: polygon(
50% 1%, 97% 25%, 97% 75%, 50% 99%, 3% 75%, 3% 25%
);
}
.hex:first-child {
grid-row-start: 1;
grid-column: 2 / span 2;
}
.hex:first-child p.hex-title {
left: 89px;
top: -125px;
}
.hex:nth-child(2) {
grid-row-start: 1;
grid-column: 4 / span 2;
}
.hex:nth-child(2) p.hex-title {
right: 290px;
top: -125px;
}
.hex:nth-child(3) {
grid-row-start: 3;
grid-column: 4 / span 2;
}
.hex:nth-child(3) .hex-title {
bottom: -72px;
left: 508px;
}
.hex:nth-child(4) {
grid-row-start: 2;
grid-column: 5 / span 3;
}
.hex:nth-child(4) p.hex-title {
right: 175px;
bottom: 10px
}
.hex:nth-child(5) {
grid-row-start: 2;
grid-column: 3 / span 2;
}
.hex:nth-child(5) p.hex-title {
left: 200px;
bottom: 20px;
}
@media(max-width: 1024px) {
.hex:first-child p.hex-title {
left: 89px;
top: -50px;
}
.hex:nth-child(2) p.hex-title {
right: 63px;
top: -40px;
}
.hex:nth-child(3) .hex-title {
bottom: -187px;
left: 404px;
}
.hex:nth-child(4) p.hex-title {
right: -70px;
bottom: 15px;
}
.hex:nth-child(5) p.hex-title {
left: 220px;
bottom: 15px;
}
}
.about-image-info-1:last-child {
margin-bottom: 0px !important;
}
</style>
<div class="first-section test-section">
<h2 data-aos="fade-up" data-aos-duration="3000"><?= $title; ?></h2>
<div class="row" data-aos="fade-up" data-aos-easing="linear" data-aos-duration="2500" >
<div class="col-sm-9">
<div class="abt-main-description">
<?= html($first_section_description); ?>
</div>
</div>
<div class="col-sm-3">
<?php foreach ($first_section_logos as $logo): ?>
<div class="about-image">
<img src="image/<?= $logo['image']; ?>" alt="logo">
</div>
<?php endforeach ?>
</div>
</div>
</div>
<div class="second-section">
<h2 data-aos="fade-up" data-aos-duration="3000"><?= $second_section_title; ?></h2>
<div class="row" data-aos="fade-up" data-aos-easing="linear" data-aos-duration="2500" >
<div class="col-sm-12">
<div class="abt-main-description desc-1">
<?= html($second_section_description_1); ?>
</div>
</div>
<div class="col-md-12">
<div class="hexagon-gallery">
<?php foreach ($second_section_logos as $logo): ?>
<div class="hex">
<div class="clip-path">
<img class="hex-img" src="image/<?= $logo['image']; ?>" alt="<?= $logo['title']; ?>">
</div>
<p class="hex-title"><?= $logo['title']; ?></p>
</div>
<?php endforeach ?>
</div>
<div class="hex-mobile-only">
<div class="hex-mobile-container">
<?php foreach ($second_section_logos as $logo): ?>
<div class="hex-mobile-wrap">
<img class="" src="image/<?= $logo['image']; ?>" alt="<?= $logo['title']; ?>">
<p><?= $logo['title']; ?></p>
</div>
<?php endforeach ?>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="abt-main-description desc-2">
<?= html($second_section_description_2); ?>
</div>
</div>
</div>
</div>
<div class="third-section">
<div class="row" data-aos="fade-up" data-aos-easing="linear" data-aos-duration="2500" >
<div class="col-sm-12">
<img src="image/<?= $third_section_vision_image; ?>" alt="vision logo">
<h2><?= $third_section_vision_title; ?></h2>
<div class="grp-description">
<?= html($third_section_vision_statement); ?>
</div>
</div>
<div class="col-sm-12">
<img src="image/<?= $third_section_mission_image; ?>" alt="mission logo">
<h2><?= $third_section_mission_title; ?></h2>
<div class="grp-description">
<?= html($third_section_mission_statement); ?>
</div>
</div>
<div class="col-sm-12">
<h2><?= $third_section_value_statement_title; ?></h2>
</div>
<div class="col-sm-6">
<?php foreach ($third_section_logos as $key => $logo):
if($key % 2 == 1) continue;
?>
<div class="about-image-info-1">
<div class="about-info">
<div class="abt-custom-listings">
<?= html($logo['description']); ?>
</div>
</div>
<div class="about-image">
<img src="image/<?= $logo['image']; ?>" alt="logo">
</div>
</div>
<?php endforeach ?>
</div>
<div class="col-sm-6">
<?php foreach ($third_section_logos as $key => $logo):
if($key % 2 != 1) continue;
?>
<div class="about-image-info-2">
<div class="about-image">
<img src="image/<?= $logo['image']; ?>" alt="logo">
</div>
<div class="about-info">
<div class="abt-custom-listings">
<?= html($logo['description']); ?>
</div>
</div>
</div>
<?php endforeach ?>
</div>
</div>
</div>
<div class="fourth-section">
<h2 data-aos="fade-up" data-aos-duration="3000"><?= $fourth_section_title; ?></h2>
<div class="row" data-aos="fade-up" data-aos-easing="linear" data-aos-duration="2500" >
<div class="col-sm-12">
<div class="abt-main-description">
<?= html($fourth_section_description); ?>
</div>
</div>
<?php foreach ($fourth_section_logos as $logo): ?>
<div class="col-sm-4">
<div class="about-image">
<img src="image/<?= $logo['image']; ?>" alt="logo">
<?= html($logo['description']); ?>
</div>
</div>
<?php endforeach ?>
</div>
</div>
据我所知,您正在使用“重型”修改后的后端! 尝试使用标准安装,所有内容都会显示。