本文整理汇总了PHP中Slim\Slim::post方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::post方法的具体用法?PHP Slim::post怎么用?PHP Slim::post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Slim
的用法示例。
在下文中一共展示了Slim::post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRouteDefinitions
/**
* This methods will be called at application startup
* @param $appInstance
* @return void
*/
public static function addRouteDefinitions(Slim $appInstance)
{
$appInstance->post('/ajax', function () use(&$appInstance) {
$exceptionContentType = 'text/plain';
$appInstance->response->headers->set('Cache-Control', 'no-store');
try {
$contentType = EmaRpcApi::slimCallback($appInstance);
$appInstance->response->headers->set('Content-Type', $contentType);
} catch (SecurityException $e) {
$appInstance->response->setStatus(401);
$appInstance->response->headers->set('Content-Type', $exceptionContentType);
print "Unauthorized.\n" . $e->getMessage();
} catch (\RuntimeException $e) {
$appInstance->response->setStatus(400);
$appInstance->response->headers->set('Content-Type', $exceptionContentType);
print $e->getMessage();
$logger = new DbLogger();
$logger->writeException($e);
} catch (\Exception $e) {
$logger = new DbLogger();
$logger->writeException($e);
$appInstance->response->setStatus(500);
$appInstance->response->headers->set('Content-Type', $exceptionContentType);
$msg = "Server Error Occurred. Please contact us. Error code is: " . $e->getCode();
if (EMA_DEBUG === true) {
$msg = $e->getMessage() . ";\n Code: " . $e->getCode() . "\n\n\n" . $e->getTraceAsString();
}
print $msg;
}
});
if (EMA_REST_API) {
$appInstance->map('/rest/:path+', function ($path) use($appInstance) {
$appInstance->response->headers->set('Cache-Control', 'no-store');
$appInstance->response->headers->set('Content-Type', 'application/json');
$printoutError = function (\Exception $e, $status = 500) use($appInstance) {
$appInstance->response->setStatus($status);
print EmaRestApi::getErrorOutput($e);
};
try {
$rpc = EmaRestApi::rpcFactory($path, $appInstance->request->getMethod(), $appInstance);
$result = EmaRestApi::rpcCheckAndRun($rpc, $appInstance);
if (EmaRestApi::$isAddition) {
$appInstance->response->setStatus(201);
$appInstance->response->headers->set('Location', EmaRestApi::$additionRouteBase);
}
print json_encode($result);
} catch (InputError $e) {
$printoutError($e, 400);
} catch (SecurityException $e) {
$printoutError($e, 403);
} catch (NotFound $e) {
$printoutError($e, 404);
} catch (Unsupported $e) {
$printoutError($e, 415);
} catch (\Exception $e) {
$printoutError($e, 500);
}
})->via('GET', 'POST', 'DELETE');
}
}
示例2: defineRoutes
protected function defineRoutes(\Slim\Slim $app)
{
// named routes first; should an event pick the same name then at least our actions take precedence
$app->get('/event', array($this, 'index'))->name("events-index");
$app->get('/event/pending', array($this, 'pending'))->name("events-pending");
$app->map('/event/submit', array($this, 'submit'))->via('GET', 'POST')->name('event-submit');
$app->get('/event/callforpapers', array($this, 'callForPapers'))->name('event-call-for-papers');
$app->get('/event/:friendly_name', array($this, 'eventDefault'))->name("event-default");
$app->get('/event/:friendly_name/details', array($this, 'details'))->name("event-detail");
$app->get('/event/:friendly_name/comments', array($this, 'comments'))->name("event-comments");
$app->get('/event/:friendly_name/comments/:comment_hash/report', array($this, 'reportComment'))->name("event-comments-reported");
$app->get('/event/:friendly_name/schedule', array($this, 'schedule'))->name("event-schedule");
$app->get('/event/:friendly_name/schedule/list', array($this, 'scheduleList'))->name("event-schedule-list");
$app->get('/event/:friendly_name/schedule/grid', array($this, 'scheduleGrid'))->name("event-schedule-grid");
$app->get('/event/:friendly_name/talk-comments', array($this, 'talkComments'))->name("event-talk-comments");
$app->post('/event/:friendly_name/add-comment', array($this, 'addComment'))->name('event-add-comment');
$app->map('/event/:friendly_name/edit', array($this, 'edit'))->via('GET', 'POST')->name('event-edit');
$app->get('/e/:stub', array($this, 'quicklink'))->name("event-quicklink");
$app->get('/event/xhr-attend/:friendly_name', array($this, 'xhrAttend'));
$app->get('/event/xhr-unattend/:friendly_name', array($this, 'xhrUnattend'));
$app->get('/event/attend/:friendly_name', array($this, 'attend'))->name("event-attend");
$app->get('/event/unattend/:friendly_name', array($this, 'unattend'))->name("event-unattend");
$app->post('/event/action-pending-event/:friendly_name', array($this, 'actionPendingEvent'))->name("event-action-pending");
$app->get('/event/view/:eventId(/:extra+)', array($this, 'redirectFromId'))->name('event-redirect-from-id')->conditions(array('eventId' => '\\d+'));
}
示例3: defineRoutes
protected function defineRoutes(\Slim\Slim $app)
{
$app->get('/event/:eventSlug/:talkSlug', array($this, 'index'))->name('talk');
$app->post('/event/:eventSlug/:talkSlug/star', array($this, 'star'))->name('talk-star');
$app->get('/talk/:talkStub', array($this, 'quick'))->name('talk-quicklink');
$app->post('/event/:eventSlug/:talkSlug/add-comment', array($this, 'addComment'))->name('talk-add-comment');
}
示例4: defineRoutes
protected function defineRoutes(\Slim\Slim $app)
{
$app->get('/event/:eventSlug/:talkSlug', array($this, 'index'))->name('talk');
$app->post('/event/:eventSlug/:talkSlug/star', array($this, 'star'))->name('talk-star');
$app->get('/talk/:talkStub', array($this, 'quick'))->name('talk-quicklink');
$app->get('/event/:eventSlug/:talkSlug/comments/:commentHash/report', array($this, 'reportComment'))->name('talk-report-comment');
$app->post('/event/:eventSlug/:talkSlug/add-comment', array($this, 'addComment'))->name('talk-add-comment');
$app->get('/:talkId', array($this, 'quickById'))->name('talk-quick-by-id')->conditions(array('talkId' => '\\d+'));
$app->get('/talk/view/:talkId', array($this, 'quickById'))->name('talk-by-id-web1')->conditions(array('talkId' => '\\d+'));
}
示例5: generateRoutes
public function generateRoutes()
{
foreach ($this->schema->table as $table) {
$tableName = $this->_urlFriendly($table['name']);
$this->slimApp->post($this->apiBasePath . "add-" . $tableName, $this->_addRecord($table));
$this->slimApp->get($this->apiBasePath . "fetch-" . $tableName . "s", $this->_fetchRecords($table));
$this->slimApp->get($this->apiBasePath . "get-" . $tableName . "/:id", $this->_getRecord($table));
$this->slimApp->get($this->apiBasePath . "get-" . $tableName . "-by/:key/:value", $this->_getRecordBy($table));
}
}
示例6: addRoutesFromMeta
private function addRoutesFromMeta(Slim $application, ClassMetadata $meta, Controller $controller)
{
$entitiesRoute = $this->getEntitiesRoute($meta);
// Fetch entities route
$application->get($entitiesRoute, function () use($meta, $controller) {
$controller->getEntities($meta);
});
// Create entity
$application->post($entitiesRoute, function () use($meta, $controller) {
$controller->createEntity($meta);
});
$entityRoute = $this->getEntityRoute($meta, $entitiesRoute);
// Get entity
$application->get($entityRoute, function () use($meta, $controller) {
$controller->getEntity($meta, func_get_args());
});
// Update entity
$application->put($entityRoute, function () use($meta, $controller) {
$controller->updateEntity($meta, func_get_args());
});
// Patch entity
$application->patch($entityRoute, function () use($meta, $controller) {
$controller->patchEntity($meta, func_get_args());
});
// Delete entity
$application->delete($entityRoute, function () use($meta, $controller) {
$controller->deleteEntity($meta, func_get_args());
});
// Handling associated entities
foreach ($meta->getAssociationMappings() as $aName => $aData) {
$aTargetClass = $meta->getAssociationTargetClass($aName);
$aMeta = $this->getEntityMeta($aTargetClass);
$aEntitiesRoute = $entityRoute . '/' . $aName;
// Create associated entity
// allow to create entity and link source together
// POST /articles/1/tags will fetch article 1, create tag entity and
// associate it to article 1
$application->post($aEntitiesRoute, function () use($meta, $aMeta, $controller, $aData) {
$controller->createEntity($aMeta, $aData['fieldName'], $meta, func_get_args());
});
// List associated entities
$application->get($aEntitiesRoute, function () use($meta, $controller, $aData) {
$controller->getAssociatedEntities($aData['fieldName'], $meta, func_get_args());
});
// Associate two entities
// POST /articles/1/tags/2 will associate article 1 to tag 2
$aEntityRoute = $this->getEntityRoute($aMeta, $aEntitiesRoute);
$application->post($aEntityRoute, function () use($meta, $aMeta, $controller, $aData) {
$controller->associateEntities($aMeta, $aData['fieldName'], $meta, func_get_args());
});
}
return $application;
}
示例7: enable
public function enable(Slim $app)
{
$this->app = $app;
$this->config = $this->app->config('api');
$this->factory = new Factory($this->config['resources']);
// Middleware
$this->app->add(new Database());
$this->app->add(new ApiMiddleware($this->config));
// Routes
$this->app->get($this->config['prefix'] . '/:resource/:id', [$this, 'getAction'])->conditions(['id' => '\\d+'])->name('resource_get');
$this->app->get($this->config['prefix'] . '/:resource', [$this, 'listAction'])->name('resource_get_list');
$this->app->put($this->config['prefix'] . '/:resource/:id', [$this, 'putAction'])->conditions(['id' => '\\d+'])->name('resource_put');
$this->app->post($this->config['prefix'] . '/:resource', [$this, 'postAction'])->name('resource_post');
$this->app->delete($this->config['prefix'] . '/:resource/:id', [$this, 'deleteAction'])->conditions(['id' => '\\d+'])->name('resource_delete');
}
示例8: slimSetup
public static function slimSetup(\Slim\Slim &$slim, One_Scheme $scheme)
{
//TODO: read specs from behaviour options or from a file
$opt = $scheme->get('behaviorOptions.restable');
$route = $opt['route'];
// retrieve
$slim->get("/{$route}", function () use($scheme) {
One_Controller_Rest::restGetAll($scheme);
});
// retrieve one
$slim->get("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) {
One_Controller_Rest::restGet($scheme, $idOrAlias);
});
// create new
$slim->post("/{$route}", function () use($scheme) {
One_Controller_Rest::restPost($scheme);
});
// update existing
$slim->put("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) {
One_Controller_Rest::restPut($scheme, $idOrAlias);
});
// delete existing
$slim->delete("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) {
One_Controller_Rest::restDelete($scheme, $idOrAlias);
});
}
示例9: registrationRoute
public static function registrationRoute(\Slim\Slim $app)
{
$app->get('/', function () use($app) {
$app->render('index.php');
});
$app->post('/form/', function () use($app) {
$app->render('index.php', ['nickname' => $_POST['nickname']]);
});
}
示例10: routes
function routes(\Slim\Slim $app)
{
$base = $this->getBasePath();
$app->post($base . '/posts/search', function () use($app) {
$app->Posts->search();
});
$app->post($base . '/posts/:id', function ($id) use($app) {
$app->Posts->getById($id);
});
$app->get($base . '/posts/:id', function ($id) use($app) {
$app->Posts->getById($id);
});
$app->post($base . '/posts', function () use($app) {
$app->Posts->save();
});
$app->delete($base . '/posts/:id', function ($id) use($app) {
$app->Posts->delete($id);
});
}
示例11: registration
public static function registration(\Slim\Slim $app)
{
// Slim縺ョCSRF蟇セ遲悶��繝ゥ繧ー繧、繝ウ繧呈怏蜉ケ蛹�
$app->add(new \Slim\Extras\Middleware\CsrfGuard());
// 繝医ャ繝励��繝シ繧ク
$app->get('/', '\\Tinitter\\Controller\\TimeLine:show');
// 謚慕ィソ荳�隕ァ
$app->get('/page/:page_num', '\\Tinitter\\Controller\\TimeLine:show');
// 譁ー隕乗兜遞ソ邉サ縲∽ソ晏ュ�
$app->post('/post/commit', '\\Tinitter\\Controller\\Post:commit');
}
示例12: addRouteDefinitions
/**
* Adds a backend routes
* @param $appInstance
* @return void
*/
public static function addRouteDefinitions(Slim $appInstance)
{
$appInstance->group('/admin', function () use($appInstance) {
$appInstance->get('/', function () {
print '<h1>A Simple Backend</h1>';
});
$appInstance->map("/chpass", function () use($appInstance) {
if (EMA_ADMIN_CHPASS) {
AdminPasswordChange_controller::process();
} else {
$appInstance->pass();
}
})->via('GET', 'POST');
$appInstance->map("/update", function () use($appInstance) {
ClassAndMethodsDispatcher::updateGPMethods();
})->via('GET', 'POST');
$appInstance->post("/login", function () use($appInstance) {
$appInstance->response->headers->set('Cache-Control', 'no-store');
if (isset($_POST['username']) && is_string($_POST['username']) && (isset($_POST['password']) && is_string($_POST['password']))) {
try {
try {
$user = new UserAuth();
} catch (SessionExpired $e) {
$user = new UserAuth();
}
$user->userLogin($_POST['username'], $_POST['password']);
if (!$user->isAdmin()) {
$user->logout();
throw new LoginIncorrect('You are not allowed to login here');
}
$appInstance->response->headers->set('Content-Type', 'application/json');
print json_encode($user->getSessionAuthData());
} catch (LoginIncorrect $e) {
$appInstance->response->headers->set('Content-Type', 'text/plain');
$appInstance->response->setStatus(400);
print $e->getMessage();
}
} else {
$appInstance->response->headers->set('Content-Type', 'text/plain');
$appInstance->response->setStatus(400);
print 'Bad request';
}
});
$appInstance->map('/logout', function () use($appInstance) {
try {
$user = new UserAuth();
if ($user->isUserLoggedInSimple()) {
$user->logout();
}
} catch (SessionExpired $e) {
}
})->via('GET', 'POST');
});
}
示例13: defineRoutes
protected function defineRoutes(\Slim\Slim $app)
{
// named routes first; should an event pick the same name then at least our actions take precedence
$app->get('/event', array($this, 'index'))->name("events-index");
$app->get('/event/pending', array($this, 'pending'))->name("events-pending");
$app->map('/event/submit', array($this, 'submit'))->via('GET', 'POST')->name('event-submit');
$app->get('/event/callforpapers', array($this, 'callForPapers'))->name('event-call-for-papers');
$app->get('/event/:friendly_name', array($this, 'details'))->name("event-detail");
$app->get('/event/:friendly_name/comments', array($this, 'comments'))->name("event-comments");
$app->get('/event/:friendly_name/schedule', array($this, 'schedule'))->name("event-schedule");
$app->get('/event/:friendly_name/talk-comments', array($this, 'talkComments'))->name("event-talk-comments");
$app->post('/event/:friendly_name/add-comment', array($this, 'addComment'))->name('event-add-comment');
$app->map('/event/:friendly_name/edit', array($this, 'edit'))->via('GET', 'POST')->name('event-edit');
$app->get('/e/:stub', array($this, 'quicklink'))->name("event-quicklink");
$app->get('/event/xhr-attend/:friendly_name', array($this, 'xhrAttend'));
$app->get('/event/xhr-unattend/:friendly_name', array($this, 'xhrUnattend'));
$app->get('/event/attend/:friendly_name', array($this, 'attend'))->name("event-attend");
$app->get('/event/unattend/:friendly_name', array($this, 'unattend'))->name("event-unattend");
$app->post('/event/action-pending-event/:friendly_name', array($this, 'actionPendingEvent'))->name("event-action-pending");
}
示例14: registration
/**
* 渡されたslimインスタンスにルートを登録
* @param \Slim\Slim $app
*/
public static function registration(\Slim\Slim $app)
{
// SlimのCSRF対策プラグインを有効化
$app->add(new \Slim\Extras\Middleware\CsrfGuard());
// トップページ
$app->get('/', '\\Tinitter\\Controller\\TimeLine:show');
// 投稿一覧
$app->get('/page/:page_num', '\\Tinitter\\Controller\\TimeLine:show');
// 新規投稿系、保存
$app->post('/post/commit', '\\Tinitter\\Controller\\Post:commit');
}
示例15: _initRoutes
private function _initRoutes()
{
$this->_slim->contentType('application/json');
$this->_slim->get('/basket/', array($this, 'getBaskets'));
$this->_slim->get('/product/', array($this, 'getProducts'));
$this->_slim->get('/basket/:id', array($this, 'getBasket'));
$this->_slim->get('/basket/:id/item/', array($this, 'getBasketItems'));
$this->_slim->get('/basket/:id/item/:prodId', array($this, 'getBasketItem'));
$this->_slim->post('/basket/:id/item/', array($this, 'postBasketItem'));
$this->_slim->put('/basket/:id/item/:prodId', array($this, 'putBasketItem'));
$this->_slim->delete('/basket/:id/item/:prodId', array($this, 'deleteBasketItem'));
}