Hi, Im new CI user and writing php is my hobby from some years. I want to make football manager to play with my friends. So the most important part of my code is my Match Engine, where I calculate data from my players, team tactics, reffer, weather and etc. Have 8 leagues, 16 teams every league and 8 matches per round/league every day. I make controller that is a cronjob:
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Engine extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('League_model', 'league');
$this->load->model('Fixture_model', 'fixture');
$this->load->model('Team_model', 'team');
$this->load->model('Player_model', 'player');
$this->load->model('Reffer_model', 'reffer');
$this->load->model('Match_model', 'match');
}
public function run($id)
{
//load the current league
$league = $this->league->getLeague($id);
//load all fixtures from this league for this round
$fixtures = $this->fixture->getFixtures($league['id_league'], $league[$current_round]);
foreach ($fixtures as $fixture) {
//load reffer, home team and away team for every match
$reffer = $this->reffer->getReffer($fixture['id_reffer']);
$homeTeamData = $this->team->getTeam($fixture['id_homeTeam']);
$homePlayerData = $this->player->getPlayer($homeTeamData['id']);
$awayTeamData = $this->team->getTeam($fixture['id_awayTeam']);
$awayPlayerData = $this->player->getPlayer($awayTeamData['id']);
//all data is passed to my match engine where match result is calculated
$resultData = $this->match->start($reffer,$homeTeamData, $homePlayerData,$awayTeamData, $awayPlayerData);
}
}
}
I that the right way to load all data to my Match_model, where I have a lot of methods that calculate the match result. My first version was to load league_model, in league_model load fixture_model and etc... big nest ot claasses hard to debug.
Is there better way to do that?