0

I try to insert the static value I have here

public static function saveBrandsAction() { $api = new Ns_Thorleif_Adminhtml_IndexController(); $arr = array(); $arr[] = array('brandId' => '123', 'name' => 'test', 'globalIdentifier' => '1020002020'); $model = Mage::getModel('thorleif/brand')->addData($arr); var_dump($model); try { $insertId = $model->save()->getId(); echo "Data successfully inserted. Insert ID: ".$insertId; } catch (Exception $e){ echo $e->getMessage(); } } 

but in the debug the query is like this

INSERT INTO `linio_brands` () VALUES () 

and my var dump looks like

object(Ns_Thorleif_Model_Brand)#314 (15) { ["_eventPrefix":protected]=> string(13) "core_abstract" ["_eventObject":protected]=> string(6) "object" ["_resourceName":protected]=> string(14) "thorleif/brand" ["_resource":protected]=> NULL ["_resourceCollectionName":protected]=> string(25) "thorleif/brand_collection" ["_cacheTag":protected]=> bool(false) ["_dataSaveAllowed":protected]=> bool(true) ["_isObjectNew":protected]=> NULL ["_data":protected]=> array(1) { [0]=> array(3) { ["brandId"]=> string(3) "123" ["name"]=> string(4) "test" ["globalIdentifier"]=> string(10) "1020002020" } } ["_hasDataChanges":protected]=> bool(true) ["_origData":protected]=> NULL ["_idFieldName":protected]=> NULL ["_isDeleted":protected]=> bool(false) ["_oldFieldsMap":protected]=> array(0) { } ["_syncFieldsMap":protected]=> array(0) { } } Data successfully inserted. Insert ID: 5

something is wrong?

2
  • 1
    try changing $arr[] to $arr Commented Jun 27, 2017 at 5:05
  • Yes it works but only to insert one row. I have many rows and for that I use the foreach and the $arr table. Commented Jun 27, 2017 at 15:17

1 Answer 1

0

I had to put it like this the Foreach with the setData and save into the foreach

foreach ($xml->Body->Brands->Brand as $row) { $arr = array('brandId' => $row->BrandId, 'name' => $row->Name); $model = Mage::getModel('thorleif/brand')->setData($arr); $model->save(); } 
1
  • You can also accept you own answer ;) Commented Jul 10, 2017 at 23:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.