Skip to content

Commit

Permalink
Creacion de Modulo Mageplaza 3
Browse files Browse the repository at this point in the history
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
PerezContrerasLuis committed Jan 26, 2022
1 parent 6fdc2db commit f7663d9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
27 changes: 27 additions & 0 deletions code/Mageplaza/HelloWorld/Model/Post.php
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;
}
}
20 changes: 20 additions & 0 deletions code/Mageplaza/HelloWorld/Model/ResourceModel/Post.php
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 code/Mageplaza/HelloWorld/Model/ResourceModel/Post/Collection.php
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');
}

}

0 comments on commit f7663d9

Please sign in to comment.