本文整理汇总了PHP中Silex\ControllerCollection::put方法的典型用法代码示例。如果您正苦于以下问题:PHP ControllerCollection::put方法的具体用法?PHP ControllerCollection::put怎么用?PHP ControllerCollection::put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\ControllerCollection
的用法示例。
在下文中一共展示了ControllerCollection::put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRoutes
protected function addRoutes(ControllerCollection $controllers)
{
$controllers->post('/key', [$this, 'create']);
$controllers->get('/key/{id}', [$this, 'show']);
$controllers->put('/key/{id}', [$this, 'update']);
$controllers->delete('/key/{id}', [$this, 'delete']);
}
示例2: connect
public function connect(Application $app)
{
$this->app = $app;
// api v1
$api = new ControllerCollection(new Route());
$api->get('/{model}', __CLASS__ . '::listAction')->assert('model', '^([a-z]+)$');
$api->get('/{model}/{id}', __CLASS__ . '::itemAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$');
$api->delete('/{model}/{id}', __CLASS__ . '::deleteAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$');
$api->put('/{model}/{id}', __CLASS__ . '::updateAction')->assert('model', '^([a-z]+)$')->assert('id', '^([a-z0-9]+)$');
$api->post('/{model}', __CLASS__ . '::createAction')->assert('model', '^([a-z]+)$');
// $model = $this->checkModel('message');
//
// foreach (range(900, 1000) as $id)
// {
// $message = new $model;
//
// $message->text = $id;
// $message->date = time();
//
// $this->dm->persist($message);
// }
//
// $this->dm->flush();
return $api;
}
示例3: createRoutes
/**
*
*
* @param ControllerCollection $factory
* @return null
*/
public function createRoutes(ControllerCollection $factory)
{
$factory->get('/files', [$this, 'get']);
$factory->get('/files/{hash}', [$this, 'getOne']);
$factory->post('/files/{hash}', [$this, 'userAction']);
$factory->delete('/files/{hash}', [$this, 'remove'])->onlyAdmin();
$factory->put('/files/{hash}', [$this, 'update'])->onlyAdmin();
$factory->get('/artists', [$this, 'getArtists']);
}
示例4: addRoutes
protected function addRoutes(ControllerCollection $controllers)
{
$controllers->post('/api/users', array($this, 'newAction'));
$controllers->get('/api/users/{name}', array($this, 'showAction'))->bind('api_users_show');
$controllers->get('/api/users', array($this, 'listAction'));
$controllers->put('/api/users/{name}', array($this, 'updateAction'));
$controllers->delete('/api/users/{name}', array($this, 'deleteAction'));
$controllers->match('api/users/{name}', array($this, 'updateAction'))->method('PATCH');
}
示例5: addCrudOperations
/**
* Setup the basic crud endpoints for this controller
* @param ControllerCollection $controller
* @return ControllerCollection
*/
public function addCrudOperations(ControllerCollection $controller)
{
$controller->get("/search", array($this, "search"));
$controller->get("/{id}", array($this, "get"));
$controller->post("/", array($this, "create"));
$controller->put("/{id}", array($this, "update"));
$controller->delete("/{id}", array($this, "delete"));
return $controller;
}
示例6: connect
/**
* {@inheritdoc}
*/
public function connect(Application $app)
{
$modelName = $this->modelName;
$prefix = sprintf('rest_controller.%s.', $this->modelName);
if (null !== $this->modelClass) {
$app[$prefix . 'model_class'] = $this->modelClass;
}
if (null !== $this->lastModifiedGetter) {
$app[$prefix . 'last_modified_getter'] = $this->lastModifiedGetter;
}
if (isset($app[$prefix . 'model_class'])) {
$app[$prefix . 'query_class'] = $app[$prefix . 'model_class'] . 'Query';
} else {
throw new \InvalidArgumentException(sprintf('You have to configure the "%s.model_class" parameter.', $prefix));
}
$controllers = new ControllerCollection($app['route_factory']);
/**
* Returns all objects
*/
$controllers->get('/', function () use($app, $prefix) {
$query = new $app[$prefix . 'query_class']();
return new Response($query->find()->exportTo($app['json_parser']), 200, array('Content-Type' => 'application/json'));
});
/**
* Returns a specific object identified by a given id
*/
$controllers->get('/{id}', function ($id) use($app, $prefix, $modelName) {
$query = new $app[$prefix . 'query_class']();
$object = $query->findPk($id);
if (!$object instanceof $app[$prefix . 'model_class']) {
throw new NotFoundHttpException(sprintf('%s with id "%d" does not exist.', ucfirst($modelName), $id));
}
$response = new Response($object->exportTo($app['json_parser']), 200, array('Content-Type' => 'application/json'));
if (isset($app[$prefix . 'last_modified_getter'])) {
$response->setLastModified($object->{$app}[$prefix . 'last_modified_getter']());
}
return $response;
});
/**
* Create a new object
*/
$controllers->post('/', function (Request $request) use($app, $prefix) {
$object = new $app[$prefix . 'model_class']();
$object->fromArray($request->request->all());
$object->save();
return new Response($object->exportTo($app['json_parser']), 201, array('Content-Type' => 'application/json'));
});
/**
* Update a object identified by a given id
*/
$controllers->put('/{id}', function ($id, Request $request) use($app, $prefix, $modelName) {
$query = new $app[$prefix . 'query_class']();
$object = $query->findPk($id);
if (!$object instanceof $app[$prefix . 'model_class']) {
throw new NotFoundHttpException(sprintf('%s with id "%d" does not exist.', ucfirst($modelName), $id));
}
$object->fromArray($request->request->all());
$object->save();
if (isset($app['monolog'])) {
$app['monolog']->addInfo(sprintf('Update %s with id %d', ucfirst($modelName), $id));
}
return new Response($object->exportTo($app['json_parser']), 200, array('Content-Type' => 'application/json'));
});
/**
* Delete a object identified by a given id
*/
$controllers->delete('/{id}', function ($id) use($app, $prefix) {
$query = new $app[$prefix . 'query_class']();
$query->filterByPrimaryKey($id)->delete();
return new Response('', 204, array('Content-Type' => 'application/json'));
});
return $controllers;
}