<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "matches".
*
* @property int $id
* @property int $tour_uniq_id
* @property int $id_matches
* @property int $home_team_id
* @property int $away_team_id
* @property string $status
* @property string $ground_type
* @property string $time_start
* @property string $round_info
*/
class Matches extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'matches';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['tour_uniq_id', 'id_matches', 'home_team_id', 'away_team_id', 'status'], 'safe'],
[['tour_uniq_id', 'id_matches', 'home_team_id', 'away_team_id'], 'integer'],
[['time_start'], 'safe'],
[['status', 'ground_type'], 'string', 'max' => 50],
[['round_info'], 'string', 'max' => 10],
[['id_matches'], 'unique'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'tour_uniq_id' => 'Tour Uniq ID',
'id_matches' => 'Id Matches',
'home_team_id' => 'Home Team ID',
'away_team_id' => 'Away Team ID',
'status' => 'Status',
'ground_type' => 'Ground Type',
'time_start' => 'Time Start',
'round_info' => 'Round Info',
];
}
}
if (is_array($data)) {
foreach ($data['tournamentInfo']['featuredMatches']['tournaments'] as $match) {
$model = new Matches();
if ($model->validate()) {
$model->tour_uniq_id = $tournament_id;
$model->id_matches = $match['events'][0]['id'];
$model->home_team_id = $match['events'][0]['homeTeam']['id'];
$model->away_team_id = $match['events'][0]['awayTeam']['id'];
$model->status = $match['events'][0]['status']['code'];
$model->ground_type = $match['events'][0]['groundType'];
$model->time_start = $match['events'][0]['startTimestamp'];
$model->round_info = $match['events'][0]['roundInfo']['name'];
$model->save();
}
}
}
$model = new Tournaments();
. Понимаю, что возможно не правильно. Где то на форумах прочитал, человек кому то подсказал..... if($model->load(Yii::$app->request->post())) {
public function actionIndex(){
$tennis = parseTennis::app("сайт")
->set(CURLOPT_REFERER, $this->referer)
->set(CURLOPT_USERAGENT, $this->header);
$resultsTour = $tennis->tournaments(date("Y-m-d"), time('d', 'm', 'Y'));
if(is_array($resultsTour)){
foreach ($resultsTour['sportItem']['tournaments'] as $request){
//$arr[]= $request;
$model = new Tournaments();
$model->name = $request['tournament']['name'];
$model->tour_unique_id = $request['tournament']['uniqueId'];
$model->category = $request['category']['name'];
$model->categori_id = $request['category']['id'];
$model->year = $request['season']['year'];
$model->year_id = rand(2000, 2999);;
if($model->load(Yii::$app->request->post()) && $model->save()) {
$model->save();
}
}
}
return $this->render('index');
}
}
<?php
namespace app\models;
use Yii;
use yii\db\ActiveRecord;
/**
* This is the model class for table "tournaments".
*
* @property int $id
* @property string $name
* @property int $tour_unique_id
* @property string $category
* @property int $categori_id
* @property int $year
* @property int $year_id
*/
class Tournaments extends ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'tournaments';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name', 'tour_unique_id', 'category', 'categori_id', 'year', 'year_id'], 'safe'],
[['tour_unique_id', 'categori_id', 'year', 'year_id'], 'integer'],
[['name'], 'string', 'max' => 255],
[['category'], 'string', 'max' => 50],
[['tour_unique_id'], 'unique'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
'tour_unique_id' => 'Tour Unique ID',
'category' => 'Category',
'categori_id' => 'Categori ID',
'year' => 'Year',
'year_id' => 'Year ID',
];
}
}
CREATE TABLE `tournaments` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`tour_unique_id` INT(11) NOT NULL UNIQUE,
`category` varchar(50) NOT NULL,
`categori_id` INT(11) NOT NULL,
`year` INT(11) NOT NULL,
`year_id` INT(11) NOT NULL,
PRIMARY KEY (`id`)
);
public function actionIndex(){
$tennis = parseTennis::app("https://www.sofascore.com/tennis")
->set(CURLOPT_REFERER, $this->referer)
->set(CURLOPT_USERAGENT, $this->header);
$results = $tennis->tournaments(date("Y-m-d"), time('d', 'm', 'Y'));
$model = new Tennis();
foreach ($results['sportItem']['tournaments'] as $request){
$model->name = $request['tournament']['name'];
$model->uniqueId = $request['tournament']['uniqueId'];
$model->category = $request['category']['name'];
$model->categori_id = $request['category']['id'];
$model->year = $request['season']['year'];
}
$model->save();
return $this->render('index', [
'model' => $model,
]);
}