link-in - רשומות קוד

חפש את הקוד שלך >

module structure

מודול - מבנה תקיות

תיקיות הבסיס למודול במגנטו

הגדרות XML לבנית המודות

etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Anagal_NewModule" setup_version="1.0.0"/>
</config>

לא לשכוח _vandor

registration.php

 \Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE, 'Learning_FirstUnit',
__DIR__
);

לא לשכוח _vandor

בדיקה אם המודול פעיל - שם ראשי + שם המודול

 php bin/magento module:status Anagal_NewNodule 

Controller

Controller/Index/Index.php

 <?php
namespace Anagal\NewModule\Controller\Index;
use Magento\Framework\App\Action\Context;

class Index extends \Magento\Framework\App\Action\Action
{

    protected $_resultPageFactory;

    public function __construct(Context $context,\Magento\Framework\View\Result\PageFactory $resultPageFactory)
    {
        $this->_resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }
    public function execute()
    {
        $resultPage = $this->_resultPageFactory->create();
        return $resultPage;
    }
} 

routers.xml - etc\frontend\routes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="custommodule" frontName="custommodule">
<module name="Anagal_CustomModule"/>
</route>
</router>
</config>

id & frontName – אותיות קטנות

הבלוק

Block\Hello.php

 שם הCLASS חייב להיות תואם לשם הקובץ .

<?php
namespace Anagal\CustomModule\Block;
class Hello extends \Magento\Framework\View\Element\Template{
public function getTitle(){
return 'Hello world!';
}
}

 

שם הקובץ חייב להיות תואם לשם הקלאס – עם אות גדולה

הכנסת layout להכנסה של הבלוק

CustomModule\view\frontend\layout\custommodule_index_index.xml

שם הקובץ כשם הfronName  ללא אותיות גדולות

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="1column">
<body>
<referenceContainer name="content">
<block class="Anagal\CustomModule\Block\Hello" name="anagal.hello" template="hello.phtml"/>
</referenceContainer>
</body>
</page>

[xlm/]

 

קובץ PHTML

Anagal/NewModule/view/frontend/templates

<?php
/* @var $block /Anagal/PopUP/Block/PopUP */
?>
<h2><?=$block->getTitle()?></h2>

מבנה המודול:

block/ form.php – איזור לפונקציות

controller/index/index.php – יורש קלאס

etc/frontend/routes.xml – מגדיר כתובת

etc/module.xml – מגדיר את המודול

view/frontend/layout/new_index_index.xml – בונה את הבלוק

view/frontend/templates – form.phtml – תבנית תצוגה

registration.php – רישום מודול

מודול נקי להורדה:

שמות לשינוי:

  1. NewModule
  2. Anagal_NewModule
  3. NewModuleBlock

 

New magento module (42 downloads)