-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creación de modelo que nos permita interactuar con nuestra Base de datos Esta sección hace uso del modulo (Pfay_contacts) creado en ---> f693d0c 1.- Creamos Nuestro modelo : el modelo no deberá contener SQL app/code/Pfay/Contacts/Model/Contact.php En el constructor invocamos a la clase resorceModel 2.- Creamos el ( ResourceModel ) app/code/Pfay/Contacts/Model/ResourceModel/Contact.php En el constructor se especifica el nombre de la tabla [ pfay_contacts ] y el id de la misma [pfay_contacts] , tabla creada aqui ---> 08703f0 3.- Creamos la colección de objetos que nos permitirá crear objetos de la tabla app/code/Pfay/Contacts/Model/ResourceModel/Contact/Collection.php 4.- Modificaos nuestro controlador para registrar tres contactos de prueba app/code/Pfay/Contacts/Model/ResourceModel/Contact.php 5.- actualízamos , compilamos y asignamos permisos php bin/magento setup:upgrade php bin/magento setup:di:compile chmod -R 777 var/ pub/ 6.- visitamos url para insertar registros http://magento240.local/contacts/test/index 7.- Verificamos que se encuentren registrados los datos en nuestra tabla de BDD select * from pfay_contacts;
- Loading branch information
1 parent
b945677
commit 3bb22b1
Showing
4 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Pfay\Contacts\Model; | ||
|
||
use Magento\Cron\Exception; | ||
use Magento\Framework\Model\AbstractModel; | ||
|
||
/** | ||
* Contact Model | ||
* | ||
* @author Pierre FAY | ||
*/ | ||
class Contact extends AbstractModel | ||
{ | ||
/** | ||
* @var \Magento\Framework\Stdlib\DateTime | ||
*/ | ||
protected $_dateTime; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init(\Pfay\Contacts\Model\ResourceModel\Contact::class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Pfay\Contacts\Model\ResourceModel; | ||
|
||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
|
||
/** | ||
* Contact Resource Model | ||
* | ||
* @author Pierre FAY | ||
*/ | ||
class Contact extends AbstractDb | ||
{ | ||
/** | ||
* Initialize resource | ||
* | ||
* @return void | ||
*/ | ||
public function _construct() | ||
{ | ||
$this->_init('pfay_contacts', 'pfay_contacts_id'); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
code/Pfay/Contacts/Model/ResourceModel/Contact/Collection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Pfay\Contacts\Model\ResourceModel\Contact; | ||
|
||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; | ||
|
||
/** | ||
* Contact Resource Model Collection | ||
* | ||
* @author Pierre FAY | ||
*/ | ||
class Collection extends AbstractCollection | ||
{ | ||
/** | ||
* Initialize resource collection | ||
* | ||
* @return void | ||
*/ | ||
public function _construct() | ||
{ | ||
$this->_init('Pfay\Contacts\Model\Contact', 'Pfay\Contacts\Model\ResourceModel\Contact'); | ||
} | ||
} |