public function actionIndex() { $decks = Deck::find()->all(); foreach ($decks as $deck) { foreach ($deck->cards as $card) { var_dump($card->name); } } exit; $endpoint = "https://omgvamp-hearthstone-v1.p.mashape.com/cards"; $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'X-Mashape-Key: aIpC7Lq0bvmshWtxepdzWC7ywu85p13p5YcjsnMJjyZDCBCv03')); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $endpoint); $result = curl_exec($ch); curl_close($ch); $arr = json_decode($result, true); //var_dump(count($arr)); exit(); foreach ($arr as $set) { //echo $set.PHP_EOL; foreach ($set as $card) { if ($card['type'] == "Minion" || $card['type'] == "Spell" || $card['type'] == "Weapon") { //var_dump($card); exit(); $mod_card = new Card(); $mod_card->name = $card['name']; $mod_card->orig_id = $card['cardId']; $mod_card->cardSet = $card['cardSet']; $mod_card->type = $card['type']; if (isset($card['faction'])) { $mod_card->faction = $card['faction']; } if (isset($card['rarity'])) { $mod_card->rarity = $card['rarity']; } if (isset($card['cost'])) { $mod_card->cost = $card['cost']; } if (isset($card['attack'])) { $mod_card->attack = $card['attack']; } if (isset($card['health'])) { $mod_card->health = $card['health']; } if (isset($card['text'])) { $mod_card->text = $card['text']; } if (isset($card['flavor'])) { $mod_card->flavor = $card['flavor']; } if (isset($card['artist'])) { $mod_card->artist = $card['artist']; } if (isset($card['collectible'])) { $mod_card->collectible = $card['collectible']; } if (isset($card['elite'])) { $mod_card->elite = $card['elite']; } $mod_card->img = $card['img']; $mod_card->imgGold = $card['imgGold']; $mod_card->locale = $card['locale']; if ($mod_card->save()) { echo "save successful" . PHP_EOL; } else { echo "Save failed" . PHP_EOL; var_dump($mod_card->getErrors()); } echo "Done: " . $card['name'] . PHP_EOL; } } } }