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


PHP App::post方法代码示例

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


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

示例1: register

 public function register(App &$app)
 {
     $self = $this;
     $app->post('/raids', function (Request $request, Response $response) use(&$self) {
         return $self->responseRaids($request, $response)->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Content-type', 'application/json');
     });
     $app->options('/raids', function (Request $request, Response $response, $args) use(&$self) {
         return $response->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Access-Control-Allow-Headers', 'Content-Type, X-AUTH-USER, X-AUTH-TOKEN');
     });
     $app->post('/raids/add', function (Request $request, Response $response) use(&$self) {
         return $self->responseRaidsAdd($request, $response)->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Content-type', 'application/json');
     });
     $app->options('/raids/add', function (Request $request, Response $response, $args) use(&$self) {
         return $response->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Access-Control-Allow-Headers', 'Content-Type, X-AUTH-USER, X-AUTH-TOKEN');
     });
 }
开发者ID:mroswald,项目名称:invme,代码行数:16,代码来源:Raids.php

示例2: register

 public function register(App &$app)
 {
     $self = $this;
     $app->post('/login', function (Request $request, Response $response) use(&$self) {
         return $self->responseLogin($request, $response)->withHeader('Content-type', 'application/json')->withHeader('Access-Control-Allow-Origin', '*');
     });
     $app->options('/login', function (Request $request, Response $response, $args) use(&$self) {
         return $response->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Access-Control-Allow-Headers', 'Content-Type');
     });
     $app->post('/login/check', function (Request $request, Response $response) use(&$self) {
         return $self->responseLoginCheck($request, $response)->withHeader('Content-type', 'application/json')->withHeader('Access-Control-Allow-Origin', '*');
     });
     $app->options('/login/check', function (Request $request, Response $response, $args) use(&$self) {
         return $response->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Access-Control-Allow-Headers', 'Content-Type');
     });
 }
开发者ID:mroswald,项目名称:invme,代码行数:16,代码来源:Login.php

示例3: testPostRoute

 public function testPostRoute()
 {
     $path = '/foo';
     $callable = function ($req, $res) {
         // Do something
     };
     $app = new App();
     $route = $app->post($path, $callable);
     $this->assertInstanceOf('\\Slim\\Route', $route);
     $this->assertAttributeContains('POST', 'methods', $route);
 }
开发者ID:hidayat365,项目名称:phpindonesia.or.id-membership2,代码行数:11,代码来源:AppTest.php

示例4: setRoute

 /**
  * @param string $method
  * @param string $route
  * @param object $routerClass
  * @param string $callback
  * @param Secured $secured
  * @throws \Exception
  */
 private function setRoute($method, $route, $routerClass, $callback, $secured)
 {
     $method = strtoupper($method);
     $easyRoute = new Route($route, $routerClass, $callback, $secured, $this);
     if ($method === 'GET') {
         $this->app->get($route, array($easyRoute, 'call'));
     } elseif ($method === 'PUT') {
         $this->app->put($route, array($easyRoute, 'call'));
     } elseif ($method === 'POST') {
         $this->app->post($route, array($easyRoute, 'call'));
     } elseif ($method === 'DELETE') {
         $this->app->delete($route, array($easyRoute, 'call'));
     } else {
         throw new \Exception('Unsupported HTTP method ' . $method);
     }
 }
开发者ID:tarienna,项目名称:easy-rest,代码行数:24,代码来源:EasyRest.php

示例5: App

 */
// config
$debug = false;
if (defined("DEBUG")) {
    $debug = true;
}
// Make a Slim App
// $app = new App($c)
$app = new App(['settings' => ['debug' => $debug, 'whoops.editor' => 'sublime']]);
$app->add(new WhoopsMiddleware());
// Home
$app->get('/', 'App\\Controllers\\HomeController:index');
$app->get('/code', 'App\\Controllers\\HomeController:code');
$app->get('/tos', 'App\\Controllers\\HomeController:tos');
$app->get('/debug', 'App\\Controllers\\HomeController:debug');
$app->post('/debug', 'App\\Controllers\\HomeController:postDebug');
// User Center
$app->group('/user', function () {
    $this->get('', 'App\\Controllers\\UserController:index');
    $this->get('/', 'App\\Controllers\\UserController:index');
    $this->post('/checkin', 'App\\Controllers\\UserController:doCheckin');
    $this->get('/node', 'App\\Controllers\\UserController:node');
    $this->get('/node/{id}', 'App\\Controllers\\UserController:nodeInfo');
    $this->get('/profile', 'App\\Controllers\\UserController:profile');
    $this->get('/invite', 'App\\Controllers\\UserController:invite');
    $this->post('/invite', 'App\\Controllers\\UserController:doInvite');
    $this->get('/edit', 'App\\Controllers\\UserController:edit');
    $this->post('/password', 'App\\Controllers\\UserController:updatePassword');
    $this->post('/sspwd', 'App\\Controllers\\UserController:updateSsPwd');
    $this->post('/method', 'App\\Controllers\\UserController:updateMethod');
    $this->get('/sys', 'App\\Controllers\\UserController:sys');
开发者ID:SharkIng,项目名称:ss-panel,代码行数:31,代码来源:routes.php

示例6: function

        $data = ['message' => $exception->getMessage()];
        return $container->get('response')->withStatus(500)->withHeader('Content-Type', 'application/json')->write(json_encode($data));
    };
};
//Register authentication container Dependency
$container['auth'] = function ($container) {
    return new BB8\Emoji\Auth($container);
};
//Initialize the slim app
$app = new App($container);
//Add middleware at app level
$app->add('BB8\\Emoji\\Middleware:init');
//Index page
$app->get('/', 'BB8\\Emoji\\Controllers\\UserController:index');
//Create new user
$app->post('/signup', 'BB8\\Emoji\\Controllers\\UserController:create');
//Login Route
$app->post('/auth/login', 'BB8\\Emoji\\Controllers\\UserController:login');
//Logout Route
$app->get('/auth/logout', 'BB8\\Emoji\\Controllers\\UserController:logout')->add('BB8\\Emoji\\Middleware:authorize');
//List all emojis Route
$app->get('/emojis', 'BB8\\Emoji\\Controllers\\EmojiController:index');
//Gets an emoji
$app->get('/emojis/{id}', 'BB8\\Emoji\\Controllers\\EmojiController:show');
//Adds a new Emoji
$app->post('/emojis', 'BB8\\Emoji\\Controllers\\EmojiController:create')->add('BB8\\Emoji\\Middleware:authorize');
//Updates an Emoji
$app->put('/emojis/{id}', 'BB8\\Emoji\\Controllers\\EmojiController:update')->add('BB8\\Emoji\\Middleware:authorize');
//Updates an Emoji Keyword
$app->put('/emojis/{id}/{kId}', 'BB8\\Emoji\\Controllers\\EmojiController:updateKey')->add('BB8\\Emoji\\Middleware:authorize');
//Partially Updates an Emoji
开发者ID:andela-gjames,项目名称:Emoji-API,代码行数:31,代码来源:route.php

示例7: Container

require_once 'src/zelory/diskonmania/DB.php';
$container = new Container();
$container['foundHandler'] = function () {
    return new RequestResponseArgs();
};
$app = new App($container);
$app->get('/', function (Request $request, Response $response) {
    $response->getBody()->write('<script type="text/javascript">url = window.location.href + "doc"; window.location = url;</script>');
    return $response->withStatus(200)->withHeader('Content-Type', 'text/html');
});
$app->post('/login', function (Request $request, Response $response) {
    try {
        $params = $request->getQueryParams();
        $user = User::login($params['username'], $params['password']);
        if ($user == null) {
            throw new Exception("Invalid username or password!");
        }
        return ResultWrapper::getResult($user, $response);
    } catch (Exception $e) {
        return ResultWrapper::getError($e->getMessage(), $response);
    }
});
$app->post('/register', function (Request $request, Response $response) {
    try {
        $params = $request->getQueryParams();
        $user = User::register($params['username'], $params['name'], $params['password']);
        if ($user == null) {
            throw new Exception("Invalid username or password!");
        }
        return ResultWrapper::getResult($user, $response);
    } catch (Exception $e) {
        return ResultWrapper::getError($e->getMessage(), $response);
开发者ID:zetbaitsu,项目名称:DiskonMania-API,代码行数:32,代码来源:index.php

示例8: bootStrap

 /**
  * Add a repository to your Slim App
  * @param App $app
  * @param Repository $repository
  * @return App the given app for chaining
  */
 public function bootStrap(App $app, Repository $repository)
 {
     $baseUrl = '/' . self::parseRepoName($repository->getEntityClass()->getShortName());
     /**
      * Get the whole collection.
      */
     $app->get($baseUrl, function (Request $request, Response $response) use($repository) {
         return $response->write(self::output($repository->findAll()))->withHeader('Content-Type', 'application/json');
     });
     /**
      * Delete the whole collection.
      */
     $app->delete($baseUrl, function (Request $request, Response $response) use($repository) {
         $repository->deleteAll();
     });
     /**
      * Add a new entity to the collection.
      */
     $app->post($baseUrl, function (Request $request, Response $response) use($repository) {
         $body = self::getBody($request->getBody(), $repository->getEntityClass(), $response);
         if ($body instanceof Response) {
             return $body;
         } else {
             // Store the entity
             $repository->insert($body);
             return $response->withStatus(Status::CREATED)->withHeader('Content-Type', 'application/json')->write(self::output($body));
         }
     });
     if ($this->showCheckPage) {
         /**
          * Display the repository check page.
          */
         $app->get($baseUrl . '/check', function (Request $request, Response $response) use($repository) {
             $repository->checkDatabase();
         });
     }
     $entityUrl = $baseUrl . '/{id}';
     /**
      * Get a single entity.
      */
     $app->get($entityUrl, function (Request $request, Response $response, $args) use($repository) {
         $entity = $repository->get($args['id']);
         if ($entity) {
             return $response->write(self::output($entity))->withHeader('Content-Type', 'application/json');
         }
         return $response->withStatus(Status::NOT_FOUND);
     });
     /**
      * Delete a single entity
      */
     $app->delete($entityUrl, function (Request $request, Response $response, $args) use($repository) {
         $repository->delete($args['id']);
     });
     /**
      * Replace a single entity
      */
     $app->put($entityUrl, function (Request $request, Response $response, $args) use($repository) {
         $body = self::getBody($request->getBody(), $repository->getEntityClass(), $response);
         if ($body instanceof Response) {
             return $body;
         } else {
             // Store the entity
             $repository->getIdProperty()->setValue($body, $args['id']);
             $repository->update($body);
             return $response->withHeader('Content-Type', 'application/json')->write(self::output($body));
         }
     });
     return $app;
 }
开发者ID:datado,项目名称:slim,代码行数:75,代码来源:Slim.php

示例9: function

$app->post('/', function (\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) {
    $postParams = $request->getParsedBody();
    /** @var \Slim\Flash\Messages $flash */
    $flash = $this->get('flash');
    try {
        \Assert\lazy()->that($postParams['email'], 'email')->notEmpty('Email must be provided')->email('Email must be valid')->verifyNow();
    } catch (Assert\LazyAssertionException $e) {
        $flash->addMessage('error', $e->getMessage());
        return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('getForm') . '?' . http_build_query(['email' => $postParams['email']]));
    }
    /** @var ExtendedPdo $pdo */
    $pdo = $this->get('pdo');
    $stm = "SELECT * FROM indiegogo WHERE Email = :email";
    $bind = ['email' => $postParams['email']];
    $sth = $pdo->perform($stm, $bind);
    $result = $sth->fetch(PDO::FETCH_ASSOC);
    if (!$result) {
        $flash->addMessage('error', 'No entry found for that email');
        return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('getForm') . '?' . http_build_query(['email' => $postParams['email']]));
    }
    try {
        if ($result['Perk ID'] == 3613098) {
            \Assert\lazy()->that($postParams, 'Shirt Type')->keyExists('shirtType', 'You must select a shirt type')->notEmptyKey('shirtType', 'You must select a shirt type')->that($postParams, 'Shirt Size')->keyExists('shirtSize', 'You must select a shirt size')->notEmptyKey('shirtSize', 'You must select a shirt size')->verifyNow();
        } elseif ($result['Perk ID'] == 3633662) {
            \Assert\lazy()->that($postParams, 'Hoodie Size')->keyExists('hoodieSize', 'You must select a hoodie size')->notEmptyKey('hoodieSize', 'You must select a hoodie size')->verifyNow();
        }
    } catch (Assert\LazyAssertionException $e) {
        /** @var \Assert\InvalidArgumentException[] $errorExceptions */
        $errorExceptions = $e->getErrorExceptions();
        foreach ($errorExceptions as $errorException) {
            $flash->addMessage('error', $errorException->getMessage());
        }
        return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('getForm') . '?' . http_build_query(['email' => $postParams['email']]));
    } catch (\Exception $e) {
        $flash->addMessage('error', $e->getMessage());
        return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('getForm') . '?' . http_build_query(['email' => $postParams['email']]));
    }
    /*
     * Save results and redirect
     */
    try {
        $qf = new QueryFactory('mysql');
        /** @var SqlQuery\Mysql\Update $update */
        $update = $qf->newUpdate();
        $update->table('indiegogo')->where('Email = :email')->bindValue('email', $postParams['email']);
        if (!empty($postParams['shirtType'])) {
            $update->set('shirtType', ':shirtType')->bindValue('shirtType', $postParams['shirtType']);
        }
        if (!empty($postParams['shirtSize'])) {
            $update->set('shirtSize', ':shirtSize')->bindValue('shirtSize', $postParams['shirtSize']);
        }
        if (!empty($postParams['hoodieSize'])) {
            $update->set('hoodieSize', ':hoodieSize')->bindValue('hoodieSize', $postParams['hoodieSize']);
        }
        /** @var ExtendedPdo $pdo */
        $pdo = $this->get('pdo');
        $stm = $update->getStatement();
        $sth = $pdo->perform($stm, $update->getBindValues());
    } catch (\Exception $e) {
        $flash->addMessage('error', 'Problem updating: exception thrown when updating');
        return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('getForm') . '?' . http_build_query(['email' => $postParams['email']]));
    }
    $flash->addMessage('info', 'Preferences saved. We will ship your perk ASAP!');
    return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('getForm') . '?' . http_build_query(['email' => $postParams['email']]));
})->setName('postForm');
开发者ID:OSMIHelp,项目名称:osmihelp.org,代码行数:65,代码来源:index.php

示例10: Container

use Psr\Http\Message\ResponseInterface as Response;
$container = new Container();
$app = new App($container);
$app->post('/', function (Request $request, Response $response) {
    $fileName = $_FILES['file']['name'];
    $pathInfo = pathinfo($fileName);
    $extension = $pathInfo['extension'];
    // TODO: Do some validation here for extension type
    $fileConverter = new \PNGify\FileConverter($_FILES['file']['tmp_name'], $extension);
    $config = (require './config.php');
    $fileConverter->setMappings($config['extensions']);
    try {
        $image = $fileConverter->toImage();
    } catch (\PNGify\Exceptions\InvalidFileExtension $e) {
        $response = $response->withStatus(400);
        /** @var \Psr\Http\Message\StreamInterface $body */
        $body = $response->getBody();
        $body->write(json_encode(['error' => 'Invalid file extension']));
        $response = $response->withHeader('Content-Type', 'application/json');
        $response = $response->withHeader('Content-Disposition', 'inline; filename="' . $pathInfo['filename'] . '.png"');
        $response = $response->withBody($body);
        return $response;
    }
    $response = $response->withHeader('Content-Type', 'image/png');
    $body = $response->getBody();
    $body->write($image);
    $response = $response->withBody($body);
    return $response;
});
$app->get('/', function (Request $request, Response $response) {
    $body = $response->getBody();
    $body->write(file_get_contents('./static/templates/index.html'));
开发者ID:simonbowen,项目名称:pngify,代码行数:32,代码来源:index.php

示例11: App

use Psr\Http\Message\ResponseInterface as Response;
use Slim\App;
// Initialize server
require 'vendor/autoload.php';
require 'Message.php';
$app = new App();
$database = new medoo(['database_type' => 'sqlite', 'database_file' => './database.sqlite']);
$message = new Message($database);
/*
 * Define server API endpoints
 */
// Main UI
$app->get('/', function (Request $request, Response $response) {
    return readfile('interface.html');
});
// Update chat endpoint for polling
// returns all messages after a specific timestamp
$app->get('/chat/{timestamp:\\d+}', function (Request $request, Response $response, $args) use($message) {
    $messages = $message->getAfter((int) $args['timestamp']);
    $response = $response->withHeader('Content-Type', 'application/json');
    return $response->getBody()->write(json_encode($messages));
});
// Main chat function: emit a message to the global chat
// messages take the JSON format {"user": "Peter", "message": "hello world"}
$app->post('/chat', function (Request $request, Response $response) use($message) {
    $data = $request->getParsedBody();
    $message->create($data['name'], $data['message']);
    return $response->withStatus(204);
});
// Start the application
$app->run();
开发者ID:jakobbuis,项目名称:bunq,代码行数:31,代码来源:index.php


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