|
||||
| ||||
|
|||||||
| OOTP Mods Logos, roster packs, historical databases, OOTP tools, FaceGen files... it's all here! |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
All Star Starter
Join Date: Dec 2005
Posts: 1,685
|
OOWP For Developers Part 4: Build a custom module step 2
OOWP For Developers Part 4:
Building a Custom Module Step 2: The Public Controller and View In step 1 of this tutorial, we began our journey down the rabbit hole of module development by first creating a module using the Module Builder tool, adding permissions and a custom database setting entry via a Bonfire Migration and creating a page in the Settings context by editing a settings controller and view. Now comes the fun part, the public controller and view that will load the team stats and display them to the user in the public portion of the site. Here's what our final page will look like before we submit the form: ![]() And after ![]() The View Controller As I stated in the previous step, to allow users to access a public page for your module, you need to have a PHP file named to match your module name in the modules controllers folder. The Bonfire module builder created such a file for us, so let's open it up ("bonfire/modules/statslist/controllers/statslist.php"). Replace the _constuct function with what you see here: Code:
public function __construct()
{
parent::__construct();
$this->lang->load('statslist');
}
Now for the meat of the class. Copy the following code for the index() function replacing it if it's already there: Code:
public function index()
{
$settings = $this->settings_lib->find_all();
$this->load->model('ootp_web_toolkit/leagues_model');
$this->load->model('ootp_web_toolkit/teams_model');
$years = $this->leagues_model->get_all_seasons($settings['ootp.league_id']);
if ($this->input->post('submit'))
{
$team_id = ($this->input->post('team_id') ? $this->input->post('team_id') : false);
$year = ($this->input->post('year')? $this->input->post('year') : false);
if ($team_id !== false)
{
$this->load->model('ootp_web_toolkit/players_model');
$records = array (
'Batting'=>$this->players_model->get_current_stats(2,$settings['ootp.league_id'], $year, $team_id),
'Pitching'=>$this->players_model->get_current_stats(1,$settings['ootp.league_id'], $year, $team_id)
);
Template::set('records',$records);
Template::set('league_year',$year);
Template::set('team_details',$this->teams_model->select('team_id, name, nickname, logo_file')->find($team_id));
}
}
$this->load->helper('form');
$this->load->helper('url');
$this->load->helper('ootp_web_toolkit/general');
Template::set('teams',$this->teams_model->get_teams_array(($settings['statslist.limit_to_primary'] == 1) ? $settings['ootp.league_id'] : false));
Template::set('years',$years);
Template::set('settings',$settings);
Template::set_view('statslist/index');
Template::render();
}
THE VIEW FILE Browse to and find "statslist/views/index.php". Replace the Module Builder generated code with the following file: index.php ZIP file I posted the file as an attachment because it's pretty sizeable. So replace your copy of "statslist/views/index.php" with this file and open it. Let's walk through it.
If you save and upload these two files to your server and browse to the www.yousitename.com/statslist/ URL (and you have OOTP game data loaded on your server), you should be able to select a team and year and see stats similar to my own demo, North American Baseball League. Congratulations! You've just stepped through building your first OOTP module for the OOWP. Want to see the complete source for this demonstration? You can find it on Github at jfox015 -> OOTP StatsList. You can also view the working demo live at North American Baseball League. You can view the admin settings page by logging is as demo/demo. Thanks for following along. I hope this was an informative demonstration of how to create tools using the Bonfire library for usage on the OOTP Open Web Platform. Now go and get coding! Download the OOWP Today! Download the latest stable release version from the official OOWP forums page. All the documentation you need is available in the installation and setup guide. Contribute to the development and help the OOWP grow The OOWP is a 100% free and open source project. The source code is publicly available on GitHub.com. If you want to contribute to the development, simply head over to my official Github page, fork the related projects, hack the code and send pull request with your updates. It’s that simple. If you’ve built an OOWP module let me know and I’ll add it to the built on the OOWP list. Want to help test? Testing assures everything works as expected and that everyone gets the best fantasy experience possible. Simply download and test the site and log issues on the official Github issues pages. Each portion of the site has its own page and issues list so be sure to log the issue in the appropriate module portion of the site. Donate While the OOWP is free to download and use, we do very much appreciate any donations made towards its development.
__________________
OOTP Mods and Sites:
Gaming Channels:
|
|
|
|
![]() |
| Bookmarks |
|
|