-
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.
Objetivo crear los modelos para conectar a la BDD Step 1: Setup Script Step 2: Create Model Step 3: Create Resource Model Step 4: Create Resource Model Collection
- Loading branch information
1 parent
6fdc2db
commit f7663d9
Showing
3 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
namespace Mageplaza\HelloWorld\Model; | ||
class Post extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\DataObject\IdentityInterface | ||
{ | ||
const CACHE_TAG = 'mageplaza_helloworld_post'; | ||
|
||
protected $_cacheTag = 'mageplaza_helloworld_post'; | ||
|
||
protected $_eventPrefix = 'mageplaza_helloworld_post'; | ||
|
||
protected function _construct() | ||
{ | ||
$this->_init('Mageplaza\HelloWorld\Model\ResourceModel\Post'); | ||
} | ||
|
||
public function getIdentities() | ||
{ | ||
return [self::CACHE_TAG . '_' . $this->getId()]; | ||
} | ||
|
||
public function getDefaultValues() | ||
{ | ||
$values = []; | ||
|
||
return $values; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
namespace Mageplaza\HelloWorld\Model\ResourceModel; | ||
|
||
|
||
class Post extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb | ||
{ | ||
|
||
public function __construct( | ||
\Magento\Framework\Model\ResourceModel\Db\Context $context | ||
) | ||
{ | ||
parent::__construct($context); | ||
} | ||
|
||
protected function _construct() | ||
{ | ||
$this->_init('mageplaza_helloworld_post', 'post_id'); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
code/Mageplaza/HelloWorld/Model/ResourceModel/Post/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,20 @@ | ||
<?php | ||
namespace Mageplaza\HelloWorld\Model\ResourceModel\Post; | ||
|
||
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection | ||
{ | ||
protected $_idFieldName = 'post_id'; | ||
protected $_eventPrefix = 'mageplaza_helloworld_post_collection'; | ||
protected $_eventObject = 'post_collection'; | ||
|
||
/** | ||
* Define resource model | ||
* | ||
* @return void | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init('Mageplaza\HelloWorld\Model\Post', 'Mageplaza\HelloWorld\Model\ResourceModel\Post'); | ||
} | ||
|
||
} |