Difference between setValues() and addValues()

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












In magento module for the back-end part, for admin form edit tab we are using addValues() and setValues().I want to know difference between those 2 functions










share|improve this question





















  • In simple term setValues reset the value and addValue append the value
    – Murtuza Zabuawala
    41 mins ago
















up vote
1
down vote

favorite












In magento module for the back-end part, for admin form edit tab we are using addValues() and setValues().I want to know difference between those 2 functions










share|improve this question





















  • In simple term setValues reset the value and addValue append the value
    – Murtuza Zabuawala
    41 mins ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











In magento module for the back-end part, for admin form edit tab we are using addValues() and setValues().I want to know difference between those 2 functions










share|improve this question













In magento module for the back-end part, for admin form edit tab we are using addValues() and setValues().I want to know difference between those 2 functions







magento2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









Charvi Parikh

43829




43829











  • In simple term setValues reset the value and addValue append the value
    – Murtuza Zabuawala
    41 mins ago
















  • In simple term setValues reset the value and addValue append the value
    – Murtuza Zabuawala
    41 mins ago















In simple term setValues reset the value and addValue append the value
– Murtuza Zabuawala
41 mins ago




In simple term setValues reset the value and addValue append the value
– Murtuza Zabuawala
41 mins ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










You can find both function's definitions in file vendormagentoframeworkDataForm.php.




public function setValues($values)

foreach ($this->_allElements as $element)
if (isset($values[$element->getId()]))
$element->setValue($values[$element->getId()]);
else
$element->setValue(null);


return $this;




The setValues($values) function set values according to the array passed in it and set null for the keys which are not set.



Where addValues($values) function does the first part only means it only sets the keys which are available.




public function addValues($values)

if (!is_array($values))
return $this;

foreach ($values as $elementId => $value)
$element = $this->getElement($elementId);
if ($element)
$element->setValue($value);


return $this;







share|improve this answer




















  • Thank you very much
    – Charvi Parikh
    1 hour ago










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f245638%2fdifference-between-setvalues-and-addvalues%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










You can find both function's definitions in file vendormagentoframeworkDataForm.php.




public function setValues($values)

foreach ($this->_allElements as $element)
if (isset($values[$element->getId()]))
$element->setValue($values[$element->getId()]);
else
$element->setValue(null);


return $this;




The setValues($values) function set values according to the array passed in it and set null for the keys which are not set.



Where addValues($values) function does the first part only means it only sets the keys which are available.




public function addValues($values)

if (!is_array($values))
return $this;

foreach ($values as $elementId => $value)
$element = $this->getElement($elementId);
if ($element)
$element->setValue($value);


return $this;







share|improve this answer




















  • Thank you very much
    – Charvi Parikh
    1 hour ago














up vote
3
down vote



accepted










You can find both function's definitions in file vendormagentoframeworkDataForm.php.




public function setValues($values)

foreach ($this->_allElements as $element)
if (isset($values[$element->getId()]))
$element->setValue($values[$element->getId()]);
else
$element->setValue(null);


return $this;




The setValues($values) function set values according to the array passed in it and set null for the keys which are not set.



Where addValues($values) function does the first part only means it only sets the keys which are available.




public function addValues($values)

if (!is_array($values))
return $this;

foreach ($values as $elementId => $value)
$element = $this->getElement($elementId);
if ($element)
$element->setValue($value);


return $this;







share|improve this answer




















  • Thank you very much
    – Charvi Parikh
    1 hour ago












up vote
3
down vote



accepted







up vote
3
down vote



accepted






You can find both function's definitions in file vendormagentoframeworkDataForm.php.




public function setValues($values)

foreach ($this->_allElements as $element)
if (isset($values[$element->getId()]))
$element->setValue($values[$element->getId()]);
else
$element->setValue(null);


return $this;




The setValues($values) function set values according to the array passed in it and set null for the keys which are not set.



Where addValues($values) function does the first part only means it only sets the keys which are available.




public function addValues($values)

if (!is_array($values))
return $this;

foreach ($values as $elementId => $value)
$element = $this->getElement($elementId);
if ($element)
$element->setValue($value);


return $this;







share|improve this answer












You can find both function's definitions in file vendormagentoframeworkDataForm.php.




public function setValues($values)

foreach ($this->_allElements as $element)
if (isset($values[$element->getId()]))
$element->setValue($values[$element->getId()]);
else
$element->setValue(null);


return $this;




The setValues($values) function set values according to the array passed in it and set null for the keys which are not set.



Where addValues($values) function does the first part only means it only sets the keys which are available.




public function addValues($values)

if (!is_array($values))
return $this;

foreach ($values as $elementId => $value)
$element = $this->getElement($elementId);
if ($element)
$element->setValue($value);


return $this;








share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









Knight017

11311




11311











  • Thank you very much
    – Charvi Parikh
    1 hour ago
















  • Thank you very much
    – Charvi Parikh
    1 hour ago















Thank you very much
– Charvi Parikh
1 hour ago




Thank you very much
– Charvi Parikh
1 hour ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f245638%2fdifference-between-setvalues-and-addvalues%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

What does second last employer means? [closed]

One-line joke