Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
AbstractModel Class Reference
Inheritance diagram for AbstractModel:
DataObject Feed Inbox Message Role Rules Debug Selection Design Action Item Image Link Website NotifyStock Price Advanced Fulltext Product Block Page Schedule Customer Group Visitor Country Format Currency Region Purchased Item Option OptionLabel ValidationRule Store Type Element Fieldset Type AbstractTemplate Value Flag AbstractExtensibleModel Code History State State Integration Consumer Nonce Token Storage AbstractDatabase Lock Message MessageStatus Queue Counts Module Orders System Users Problem Queue Subscriber AbstractAgreement Cert Settlement Row Session Email Price Stock Rate Option QuoteIdMask Event Type AbstractIndex Rating Entity Option Vote Review Status Summary Rss AbstractNotifier AbstractItems Tax Massgenerator Customer Validator Meta Profile Query SynonymGroup SynonymReader AdminSessionInfo PasswordResetRequestEvent SendFriend CaseEntity Sitemap Swatch Calculation Design Theme File StringUtils UrlRewrite User Variable PaymentToken Tax Link Update Instance Item Option Wishlist

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Protected Member Functions

 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Abstract model class

@api @SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.NumberOfChildren) @SuppressWarnings(PHPMD.TooManyFields)

Since
100.0.2

Definition at line 19 of file AbstractModel.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data

Definition at line 172 of file AbstractModel.php.

178  {
179  $this->_registry = $registry;
180  $this->_appState = $context->getAppState();
181  $this->_eventManager = $context->getEventDispatcher();
182  $this->_cacheManager = $context->getCacheManager();
183  $this->_resource = $resource;
184  $this->_resourceCollection = $resourceCollection;
185  $this->_logger = $context->getLogger();
186  $this->_actionValidator = $context->getActionValidator();
187 
188  if (method_exists($this->_resource, 'getIdFieldName')
189  || $this->_resource instanceof \Magento\Framework\DataObject
190  ) {
191  $this->_idFieldName = $this->_getResource()->getIdFieldName();
192  }
193 
194  parent::__construct($data);
195  $this->_construct();
196  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ __sleep()

__sleep ( )
Returns
string[]

Definition at line 222 of file AbstractModel.php.

223  {
224  $properties = array_keys(get_object_vars($this));
225  $properties = array_diff(
226  $properties,
227  [
228  '_eventManager',
229  '_cacheManager',
230  '_registry',
231  '_appState',
232  '_actionValidator',
233  '_logger',
234  '_resourceCollection',
235  '_resource',
236  ]
237  );
238  return $properties;
239  }
$properties
Definition: categories.php:26

◆ __wakeup()

__wakeup ( )

Init not serializable fields

Returns
void

Definition at line 246 of file AbstractModel.php.

247  {
249  $this->_registry = $objectManager->get(\Magento\Framework\Registry::class);
250 
251  $context = $objectManager->get(\Magento\Framework\Model\Context::class);
252  if ($context instanceof \Magento\Framework\Model\Context) {
253  $this->_appState = $context->getAppState();
254  $this->_eventManager = $context->getEventDispatcher();
255  $this->_cacheManager = $context->getCacheManager();
256  $this->_logger = $context->getLogger();
257  $this->_actionValidator = $context->getActionValidator();
258  }
259  }
$objectManager
Definition: bootstrap.php:17

◆ _afterLoad()

_afterLoad ( )
protected

Processing object after load data

Returns
$this

Definition at line 575 of file AbstractModel.php.

576  {
577  $this->_eventManager->dispatch('model_load_after', ['object' => $this]);
578  $this->_eventManager->dispatch($this->_eventPrefix . '_load_after', $this->_getEventData());
579  return $this;
580  }

◆ _beforeLoad()

_beforeLoad (   $modelId,
  $field = null 
)
protected

Processing object before load data

Parameters
int$modelId
null | string$field
Returns
$this

Definition at line 561 of file AbstractModel.php.

562  {
563  $params = ['object' => $this, 'field' => $field, 'value' => $modelId];
564  $this->_eventManager->dispatch('model_load_before', $params);
565  $params = array_merge($params, $this->_getEventData());
566  $this->_eventManager->dispatch($this->_eventPrefix . '_load_before', $params);
567  return $this;
568  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _clearData()

_clearData ( )
protected

Clearing object's data

Returns
$this

Definition at line 945 of file AbstractModel.php.

946  {
947  return $this;
948  }

◆ _clearReferences()

_clearReferences ( )
protected

Clearing cyclic references

Returns
$this

Definition at line 935 of file AbstractModel.php.

936  {
937  return $this;
938  }

◆ _construct()

_construct ( )
protected

Model construct that should be used for object initialization

Returns
void

Definition at line 203 of file AbstractModel.php.

204  {
205  }

◆ _createValidatorBeforeSave()

_createValidatorBeforeSave ( )
protected

Creates validator for the model with all validation rules in it. Returns FALSE, if no validation rules exist.

Returns
\Zend_Validate_Interface|bool

Definition at line 741 of file AbstractModel.php.

742  {
743  $modelRules = $this->_getValidationRulesBeforeSave();
744  $resourceRules = $this->_getResource()->getValidationRulesBeforeSave();
745  if (!$modelRules && !$resourceRules) {
746  return false;
747  }
748 
749  if ($modelRules && $resourceRules) {
750  $validator = new \Zend_Validate();
751  $validator->addValidator($modelRules);
752  $validator->addValidator($resourceRules);
753  } elseif ($modelRules) {
754  $validator = $modelRules;
755  } else {
756  $validator = $resourceRules;
757  }
758 
759  return $validator;
760  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ _getEventData()

_getEventData ( )
protected

Get array of objects transferred to default events processing

Returns
array

Definition at line 546 of file AbstractModel.php.

547  {
548  return [
549  'data_object' => $this,
550  $this->_eventObject => $this,
551  ];
552  }

◆ _getResource()

_getResource ( )
protected

Get resource instance

Exceptions

Definition at line 470 of file AbstractModel.php.

471  {
472  if (empty($this->_resourceName) && empty($this->_resource)) {
473  throw new \Magento\Framework\Exception\LocalizedException(
474  new \Magento\Framework\Phrase('The resource isn\'t set.')
475  );
476  }
477 
478  return $this->_resource ?: \Magento\Framework\App\ObjectManager::getInstance()->get($this->_resourceName);
479  }

◆ _getValidationRulesBeforeSave()

_getValidationRulesBeforeSave ( )
protected

Template method to return validate rules for the entity

Returns
\Zend_Validate_Interface|null

Definition at line 767 of file AbstractModel.php.

768  {
769  return null;
770  }

◆ _getValidatorBeforeSave()

_getValidatorBeforeSave ( )
protected

Returns validator, which contains all rules to validate this model. Returns FALSE, if no validation rules exist.

Returns
\Zend_Validate_Interface|false

Definition at line 727 of file AbstractModel.php.

728  {
729  if ($this->_validatorBeforeSave === null) {
730  $this->_validatorBeforeSave = $this->_createValidatorBeforeSave();
731  }
733  }

◆ _hasModelChanged()

_hasModelChanged ( )
protected

Check whether model has changed data. Can be overloaded in child classes to perform advanced check whether model needs to be saved e.g. using resourceModel->hasDataChanged() or any other technique

Returns
boolean

Definition at line 614 of file AbstractModel.php.

615  {
616  return $this->hasDataChanges();
617  }

◆ _init()

_init (   $resourceModel)
protected

Standard model initialization

Parameters
string$resourceModel
Returns
void

Definition at line 213 of file AbstractModel.php.

214  {
216  $this->_idFieldName = $this->_getResource()->getIdFieldName();
217  }
_setResourceModel($resourceName, $collectionName=null)
$resourceModel
Definition: tablerates.php:10

◆ _setResourceModel()

_setResourceModel (   $resourceName,
  $collectionName = null 
)
protected

Set resource names

If collection name is omitted, resource name will be used with _collection appended

Parameters
string$resourceName
string | null$collectionName
Returns
void

Definition at line 454 of file AbstractModel.php.

455  {
456  $this->_resourceName = $resourceName;
457  if ($collectionName === null) {
458  $collectionName = $resourceName . '\\' . 'Collection';
459  }
460  $this->_collectionName = $collectionName;
461  }

◆ afterCommitCallback()

afterCommitCallback ( )

Callback function which called after transaction commit in resource model

Returns
$this

Definition at line 657 of file AbstractModel.php.

658  {
659  $this->_eventManager->dispatch('model_save_commit_after', ['object' => $this]);
660  $this->_eventManager->dispatch($this->_eventPrefix . '_save_commit_after', $this->_getEventData());
661  return $this;
662  }

◆ afterDelete()

afterDelete ( )

Processing object after delete data

Returns
$this

Definition at line 864 of file AbstractModel.php.

865  {
866  $this->_eventManager->dispatch('model_delete_after', ['object' => $this]);
867  $this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]);
868  $this->_eventManager->dispatch($this->_eventPrefix . '_delete_after', $this->_getEventData());
869  $this->storedData = [];
870  return $this;
871  }

◆ afterDeleteCommit()

afterDeleteCommit ( )

Processing manipulation after main transaction commit

Returns
$this

Definition at line 878 of file AbstractModel.php.

879  {
880  $this->_eventManager->dispatch('model_delete_commit_after', ['object' => $this]);
881  $this->_eventManager->dispatch($this->_eventPrefix . '_delete_commit_after', $this->_getEventData());
882  return $this;
883  }

◆ afterLoad()

afterLoad ( )

Object after load processing. Implemented as public interface for supporting objects after load in collections

Returns
$this

Definition at line 600 of file AbstractModel.php.

601  {
602  $this->_afterLoad();
603  $this->updateStoredData();
604  return $this;
605  }

◆ afterSave()

afterSave ( )

Processing object after save data

Returns
$this

Definition at line 814 of file AbstractModel.php.

815  {
816  $this->cleanModelCache();
817  $this->_eventManager->dispatch('model_save_after', ['object' => $this]);
818  $this->_eventManager->dispatch('clean_cache_by_tags', ['object' => $this]);
819  $this->_eventManager->dispatch($this->_eventPrefix . '_save_after', $this->_getEventData());
820  $this->updateStoredData();
821  return $this;
822  }

◆ beforeDelete()

beforeDelete ( )

Processing object before delete data

Returns
$this
Exceptions

Definition at line 845 of file AbstractModel.php.

846  {
847  if (!$this->_actionValidator->isAllowed($this)) {
848  throw new \Magento\Framework\Exception\LocalizedException(
849  new \Magento\Framework\Phrase('Delete operation is forbidden for current area')
850  );
851  }
852 
853  $this->_eventManager->dispatch('model_delete_before', ['object' => $this]);
854  $this->_eventManager->dispatch($this->_eventPrefix . '_delete_before', $this->_getEventData());
855  $this->cleanModelCache();
856  return $this;
857  }

◆ beforeLoad()

beforeLoad (   $identifier,
  $field = null 
)

Process operation before object load

Parameters
string$identifier
string | null$field
Returns
void
Since
101.0.0

Definition at line 590 of file AbstractModel.php.

591  {
592  $this->_beforeLoad($identifier, $field);
593  }

◆ beforeSave()

beforeSave ( )

Processing object before save data

Returns
$this

Definition at line 689 of file AbstractModel.php.

690  {
691  if (!$this->getId()) {
692  $this->isObjectNew(true);
693  }
694  $this->_eventManager->dispatch('model_save_before', ['object' => $this]);
695  $this->_eventManager->dispatch($this->_eventPrefix . '_save_before', $this->_getEventData());
696  return $this;
697  }

◆ cleanModelCache()

cleanModelCache ( )

Remove model object related cache

Returns
$this

Definition at line 800 of file AbstractModel.php.

801  {
802  $tags = $this->getCacheTags();
803  if ($tags !== false) {
804  $this->_cacheManager->clean($tags);
805  }
806  return $this;
807  }

◆ clearInstance()

clearInstance ( )

Clearing object for correct deleting by garbage collector

Returns
$this

Definition at line 922 of file AbstractModel.php.

923  {
924  $this->_clearReferences();
925  $this->_eventManager->dispatch($this->_eventPrefix . '_clear', $this->_getEventData());
926  $this->_clearData();
927  return $this;
928  }

◆ dataHasChangedFor()

dataHasChangedFor (   $field)

Compare object data with original data

Parameters
string$field
Returns
bool

Definition at line 438 of file AbstractModel.php.

439  {
440  $newData = $this->getData($field);
441  $origData = $this->getOrigData($field);
442  return $newData != $origData;
443  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ delete()

delete ( )

Delete object from database

Returns
$this
Exceptions

Definition at line 833 of file AbstractModel.php.

834  {
835  $this->_getResource()->delete($this);
836  return $this;
837  }

◆ getCacheTags()

getCacheTags ( )

Get list of cache tags applied to model object. Return false if cache tags are not supported by model

Returns
array|false

Definition at line 778 of file AbstractModel.php.

779  {
780  $tags = false;
781  if ($this->_cacheTag) {
782  if ($this->_cacheTag === true) {
783  $tags = [];
784  } else {
785  if (is_array($this->_cacheTag)) {
786  $tags = $this->_cacheTag;
787  } else {
788  $tags = [$this->_cacheTag];
789  }
790  }
791  }
792  return $tags;
793  }

◆ getCollection()

getCollection ( )

Retrieve collection instance

@TODO MAGETWO-23541: Incorrect dependencies between Model\AbstractModel and Data\Collection\Db from Framework

Returns
\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
Deprecated:
because collections should be used directly via factory

Definition at line 520 of file AbstractModel.php.

521  {
522  return $this->getResourceCollection();
523  }

◆ getEntityId()

getEntityId ( )

Retrieve entity id

Returns
mixed

Definition at line 901 of file AbstractModel.php.

902  {
903  return $this->_getData('entity_id');
904  }

◆ getEventPrefix()

getEventPrefix ( )

Returns _eventPrefix

Returns
string

Definition at line 980 of file AbstractModel.php.

◆ getId()

getId ( )

Identifier getter

Returns
mixed

Definition at line 288 of file AbstractModel.php.

289  {
290  return $this->_getData($this->_idFieldName);
291  }

◆ getIdFieldName()

getIdFieldName ( )

Id field name getter

Returns
string

Definition at line 278 of file AbstractModel.php.

◆ getOrigData()

getOrigData (   $key = null)

Get object original data

Parameters
string$key
Returns
mixed

Definition at line 402 of file AbstractModel.php.

403  {
404  if ($key === null) {
405  return $this->_origData;
406  }
407  if (isset($this->_origData[$key])) {
408  return $this->_origData[$key];
409  }
410  return null;
411  }

◆ getResource()

getResource ( )

Retrieve model resource

Returns
\Magento\Framework\Model\ResourceModel\Db\AbstractDb
Deprecated:
because resource models should be used directly

Definition at line 891 of file AbstractModel.php.

892  {
893  return $this->_getResource();
894  }

◆ getResourceCollection()

getResourceCollection ( )

Get collection instance

@TODO MAGETWO-23541: Incorrect dependencies between Model\AbstractModel and Data\Collection\Db from Framework

Exceptions

Definition at line 499 of file AbstractModel.php.

500  {
501  if (empty($this->_resourceCollection) && empty($this->_collectionName)) {
502  throw new \Magento\Framework\Exception\LocalizedException(
503  new \Magento\Framework\Phrase('Model collection resource name is not defined.')
504  );
505  }
506  return $this->_resourceCollection ? clone $this
507  ->_resourceCollection : \Magento\Framework\App\ObjectManager::getInstance()
508  ->create(
509  $this->_collectionName
510  );
511  }

◆ getResourceName()

getResourceName ( )

Retrieve model resource name

Returns
string

Definition at line 486 of file AbstractModel.php.

487  {
488  return $this->_resource ? get_class($this->_resource) : ($this->_resourceName ? $this->_resourceName : null);
489  }

◆ getStoredData()

getStoredData ( )

Model StoredData getter

Returns
array

Definition at line 970 of file AbstractModel.php.

◆ hasDataChanges()

hasDataChanges ( )

Check if initial object data was changed.

Initial data is coming to object constructor. Flag value should be set up to true after any external data changes

Returns
bool

Definition at line 328 of file AbstractModel.php.

◆ isDeleted()

isDeleted (   $isDeleted = null)

Set _isDeleted flag value (if $isDeleted parameter is defined) and return current flag value

Parameters
boolean$isDeleted
Returns
bool

Definition at line 311 of file AbstractModel.php.

312  {
314  if ($isDeleted !== null) {
315  $this->_isDeleted = $isDeleted;
316  }
317  return $result;
318  }

◆ isObjectNew()

isObjectNew (   $flag = null)

Check object state (true - if it is object without id on object just created) This method can help detect if object just created in _afterSave method problem is what in after save object has id and we can't detect what object was created in this transaction

Parameters
bool | null$flag
Returns
bool

Definition at line 673 of file AbstractModel.php.

674  {
675  if ($flag !== null) {
676  $this->_isObjectNew = $flag;
677  }
678  if ($this->_isObjectNew !== null) {
679  return $this->_isObjectNew;
680  }
681  return !(bool)$this->getId();
682  }

◆ isSaveAllowed()

isSaveAllowed ( )
Returns
bool

Definition at line 622 of file AbstractModel.php.

623  {
624  return (bool) $this->_dataSaveAllowed;
625  }

◆ load()

load (   $modelId,
  $field = null 
)

Load object data

Parameters
integer$modelId
null | string$field
Returns
$this
Deprecated:
100.1.0 because entities must not be responsible for their own loading. Service contracts should persist entities. Use resource model "load" or collections to implement service contract model loading operations.

Definition at line 535 of file AbstractModel.php.

536  {
537  $this->_getResource()->load($this, $modelId, $field);
538  return $this;
539  }

◆ save()

save ( )

Save object data

Returns
$this
Exceptions

Definition at line 646 of file AbstractModel.php.

647  {
648  $this->_getResource()->save($this);
649  return $this;
650  }

◆ setData()

setData (   $key,
  $value = null 
)

Overwrite data in the object.

The $key parameter can be string or array. If $key is string, the attribute value will be overwritten by $value

If $key is an array, it will overwrite all the data in the object.

Parameters
string | array$key
mixed$value
Returns
$this

Definition at line 345 of file AbstractModel.php.

346  {
347  if ($key === (array)$key) {
348  if ($this->_data !== $key) {
349  $this->_hasDataChanges = true;
350  }
351  $this->_data = $key;
352  } else {
353  if (!array_key_exists($key, $this->_data) || $this->_data[$key] !== $value) {
354  $this->_hasDataChanges = true;
355  }
356  $this->_data[$key] = $value;
357  }
358  return $this;
359  }
$value
Definition: gender.phtml:16

◆ setDataChanges()

setDataChanges (   $value)

Clears data changes status

Parameters
bool$value
Returns
$this

Definition at line 390 of file AbstractModel.php.

391  {
392  $this->_hasDataChanges = (bool)$value;
393  return $this;
394  }
$value
Definition: gender.phtml:16

◆ setEntityId()

setEntityId (   $entityId)

Set entity id

Parameters
int$entityId
Returns
$this

Definition at line 912 of file AbstractModel.php.

913  {
914  return $this->setData('entity_id', $entityId);
915  }

◆ setHasDataChanges()

setHasDataChanges (   $flag)
Parameters
bool$flag
Returns
void

Definition at line 631 of file AbstractModel.php.

632  {
633  $this->_hasDataChanges = $flag;
634  }

◆ setId()

setId (   $value)

Identifier setter

Parameters
mixed$value
Returns
$this

Definition at line 299 of file AbstractModel.php.

300  {
301  $this->setData($this->_idFieldName, $value);
302  return $this;
303  }
$value
Definition: gender.phtml:16

◆ setIdFieldName()

setIdFieldName (   $name)

Id field name setter

Parameters
string$name
Returns
$this

Definition at line 267 of file AbstractModel.php.

268  {
269  $this->_idFieldName = $name;
270  return $this;
271  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setOrigData()

setOrigData (   $key = null,
  $data = null 
)

Initialize object original data

@FIXME changing original data can't be available as public interface

Parameters
string$key
mixed$data
Returns
$this

Definition at line 422 of file AbstractModel.php.

423  {
424  if ($key === null) {
425  $this->_origData = $this->_data;
426  } else {
427  $this->_origData[$key] = $data;
428  }
429  return $this;
430  }

◆ unsetData()

unsetData (   $key = null)

Unset data from the object.

Parameters
null | string | array$key
Returns
$this

Definition at line 367 of file AbstractModel.php.

368  {
369  if ($key === null) {
370  $this->setData([]);
371  } elseif (is_string($key)) {
372  if (isset($this->_data[$key]) || array_key_exists($key, $this->_data)) {
373  $this->_hasDataChanges = true;
374  unset($this->_data[$key]);
375  }
376  } elseif ($key === (array)$key) {
377  foreach ($key as $element) {
378  $this->unsetData($element);
379  }
380  }
381  return $this;
382  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$element
Definition: element.phtml:12

◆ validateBeforeSave()

validateBeforeSave ( )

Validate model before saving it

Returns
$this
Exceptions

Definition at line 705 of file AbstractModel.php.

706  {
707  $validator = $this->_getValidatorBeforeSave();
708  if ($validator && !$validator->isValid($this)) {
709  $errors = $validator->getMessages();
710  $exception = new \Magento\Framework\Validator\Exception(
711  new Phrase(implode(PHP_EOL, $errors))
712  );
713  foreach ($errors as $errorMessage) {
714  $exception->addMessage(new \Magento\Framework\Message\Error($errorMessage));
715  }
716  throw $exception;
717  }
718  return $this;
719  }
$errors
Definition: overview.phtml:9

Field Documentation

◆ $_actionValidator

$_actionValidator
protected

Definition at line 156 of file AbstractModel.php.

◆ $_appState

$_appState
protected

Definition at line 151 of file AbstractModel.php.

◆ $_cacheManager

$_cacheManager
protected

Definition at line 136 of file AbstractModel.php.

◆ $_cacheTag

$_cacheTag = false
protected

Definition at line 99 of file AbstractModel.php.

◆ $_collectionName

$_collectionName
protected

Definition at line 90 of file AbstractModel.php.

◆ $_dataSaveAllowed

$_dataSaveAllowed = true
protected

Definition at line 108 of file AbstractModel.php.

◆ $_eventManager

$_eventManager
protected

Definition at line 129 of file AbstractModel.php.

◆ $_eventObject

$_eventObject = 'object'
protected

Definition at line 35 of file AbstractModel.php.

◆ $_eventPrefix

$_eventPrefix = 'core_abstract'
protected

Definition at line 26 of file AbstractModel.php.

◆ $_hasDataChanges

$_hasDataChanges = false
protected

Definition at line 48 of file AbstractModel.php.

◆ $_idFieldName

$_idFieldName = 'id'
protected

Definition at line 42 of file AbstractModel.php.

◆ $_isDeleted

$_isDeleted = false
protected

Definition at line 62 of file AbstractModel.php.

◆ $_isObjectNew

$_isObjectNew = null
protected

Definition at line 115 of file AbstractModel.php.

◆ $_logger

$_logger
protected

Definition at line 146 of file AbstractModel.php.

◆ $_origData

$_origData
protected

Definition at line 55 of file AbstractModel.php.

◆ $_registry

$_registry
protected

Definition at line 141 of file AbstractModel.php.

◆ $_resource

$_resource
protected

Definition at line 69 of file AbstractModel.php.

◆ $_resourceCollection

$_resourceCollection
protected

Definition at line 76 of file AbstractModel.php.

◆ $_resourceName

$_resourceName
protected

Definition at line 83 of file AbstractModel.php.

◆ $_validatorBeforeSave

$_validatorBeforeSave = null
protected

Definition at line 122 of file AbstractModel.php.

◆ $storedData

$storedData = []
protected

Definition at line 163 of file AbstractModel.php.


The documentation for this class was generated from the following file: