当前位置: 首页>>代码示例>>PHP>>正文


PHP Match::Create方法代码示例

本文整理汇总了PHP中Match::Create方法的典型用法代码示例。如果您正苦于以下问题:PHP Match::Create方法的具体用法?PHP Match::Create怎么用?PHP Match::Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Match的用法示例。


在下文中一共展示了Match::Create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: count

 */
chdir(dirname(__FILE__));
require '../config.php';
$number_of_matches = 2;
/* Get list of existing teams
 ******************************************************************************/
$teams = $db->fetch("SELECT id FROM Team", null, 'Team');
for ($i = 0; $i < $number_of_matches; $i++) {
    /* Assign two random opposing teams
     ******************************************************************************/
    $team_1 = $teams[mt_rand(0, count($teams) - 1)]->id;
    // Prevent second team from being the same as the first one
    do {
        $team_2 = $teams[mt_rand(0, count($teams) - 1)]->id;
    } while ($team_2 == $team_1);
    /* Generate match start dates in the near future and duration
     ******************************************************************************/
    $format = 'Y-m-d H:i:s';
    $duration = 5;
    // Duration of the match (in minutes)
    $start_time = date($format, strtotime("now +" . mt_rand(5, 25) . " minutes"));
    $end_time = date($format, strtotime("{$start_time} +{$duration} minutes"));
    /* Create the match
     ******************************************************************************/
    $match = new Match();
    $match->team_1 = $team_1;
    $match->team_2 = $team_2;
    $match->start_time = $start_time;
    $match->end_time = $end_time;
    $match->Create();
}
开发者ID:andrecosta,项目名称:SoccerWars,代码行数:31,代码来源:create-match.php

示例2: function

/* Create match
 **********************************************************************************************************************/
$app->post('/matches', function () use($app) {
    $data = json_decode($app->request->getBody(), true);
    $team_1 = $data['team_1'];
    $team_2 = $data['team_2'];
    $start_time = $data['start_time'];
    $end_time = $data['end_time'];
    // Setup the match
    $match = new Match();
    $match->team_1 = $team_1;
    $match->team_2 = $team_2;
    $match->start_time = $start_time;
    $match->end_time = $end_time;
    // Create the match
    if ($match_id = $match->Create()) {
        $app->render_json(["id" => $match_id]);
    } else {
        throw new Exception("Error creating the match", 400);
    }
});
/* Insert comment
 **********************************************************************************************************************/
$app->post('/matches/:id/comments', function ($id) use($app) {
    $data = json_decode($app->request->getBody(), true);
    $text = $data['text'];
    $user = User::GetByToken($app->request->headers->get('token'));
    if (empty($text)) {
        throw new Exception("No text in comment", 400);
    }
    // Insert the comment
开发者ID:andrecosta,项目名称:SoccerWars,代码行数:31,代码来源:index.php


注:本文中的Match::Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。