Wie kann festgestellt werden, welche Tabelle die Vorbereitungssammlungsmethode übernehmen soll?

magento.stackexchange https://magento.stackexchange.com//questions/51674

Frage

Davon Ändern Sie den Tabellennamen für Admin-Grid-Sammlungen Thread, ein Zweifel ist entstanden.

Wenn wir in unserem benutzerdefinierten Modul 2 Tabellen verwendet haben, wie können wir dann feststellen, welche Tabelle die Vorbereitungssammlungsmethode verwenden soll?

Ich warte gespannt auf Ihre Antwort!

War es hilfreich?

Lösung

Mehrere Modelle für ein Modul mit einer Tabelle für jedes Modell

Die Erstellung mehrerer Modelle für ein Modell ist einfach. Sie müssen es tun define multiple entities zu deinem Module Model resourceModel und es corresponding entity entity_id Table.

Beispiel:

        <custommodule_resource>
            <class>Amit_Custommodule_Model_Resource</class>
            <entities>
                <custommoduleone>
                    <table>custommoduleTestOne</table>
                </custommoduleone>
        <custommoduletwo>
                    <table>custommoduleTestTwo</table>
        </custommoduletwo>
            </entities>
        </custommodule_resource>

Vollständiger Modellcode für das Modul:

<models>
    <custommodule>
    <class>Amit_Custommodule_Model</class>
    <resourceModel>custommodule_resource</resourceModel>
    </custommodule>
    <custommodule_resource>
    <class>Amit_Custommodule_Model_Resource</class>
    <entities>
        <custommoduleone>
        <table>custommoduleTestOne</table>
        </custommoduleone>
        <custommoduletwo>
        <table>custommoduleTestTwo</table>
        </custommoduletwo>
    </entities>
    </custommodule_resource>
</models>

Dieses Modell bietet Ihnen zwei Modelle für ein Modul

  1. Mage::getModel('custommodule/custommoduletwo') // als Entitäten ist custommoduletwo
  2. Mage::getModel('custommodule/custommoduleone')

Prozess der Klassendefinition

Laut Magento für each Model erforderlich, um entsprechendes zu erstellen Modell, Ressource, Sammlung Klasse

Modellklasse für Modell Mage::getModel('custommodule/custommoduleone')

<?php
class Amit_Custommodule_Model_Custommoduleone extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
        $this->_init('custommodule/custommoduleone');
    }

}

Ressourcenklasse

App/Code/Community/Amit/CustomModule/Modell/Ressource/CustomModuleone.php - Weitere Informationen finden Sie unter:

<?php
class Amit_Custommodule_Model_Resource_Custommoduleone extends Mage_Core_Model_Resource_Db_Abstract
{
    /**
     * Initialize resource model
     *
     * @return void
     */
    public function _construct()
    {
        $this->_init('custommodule/custommoduleone', 'table_Primarykey');
    }
}

Sammlungsklasse:

Der Pfad der Sammlungsdatei lautet Collection.php app/code/community/Amit/Custommodule/Model/Resource/Custommoduleone

<?php
class Amit_Custommodule_Model_Resource_Custommoduleone_Collection
extends Mage_Core_Model_Resource_Db_Collection_Abstract{
    protected function _constuct(){
        $this->_init('custommodule/custommoduleone');    
    }
}

Zweites Modell:

Modellklasse

<?php
class Amit_Custommodule_Model_CustommoduleTwo extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
        $this->_init('custommodule/custommoduletwo');
    }

}

Ressourcenklasse

app/code/community/Amit/Custommodule/Model/Resource/Custommoduletwo.php

<?php
class Amit_Custommodule_Model_Resource_Custommoduletwo extends Mage_Core_Model_Resource_Db_Abstract
{
    /**
     * Initialize resource model
     *
     * @return void
     */
    public function _construct()
    {
        $this->_init('custommodule/custommoduletwo', 'table_Primarykey');
    }
}

Sammlungsklasse:

Der Pfad der Sammlungsdatei lautet Collection.php app/code/community/Amit/Custommodule/Model/Resource/Custommoduletwo

<?php
class Amit_Custommodule_Model_Resource_Custommoduletwo_Collection
extends Mage_Core_Model_Resource_Db_Collection_Abstract{
    protected function _constuct(){
        $this->_init('custommodule/custommoduletwo');    
    }
}

HINWEIS: Ich werde in Kürze mehrere Tische für ein Modell bereitstellen

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top