本文整理汇总了PHP中Slim\Http\Request::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getAttribute方法的具体用法?PHP Request::getAttribute怎么用?PHP Request::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Request
的用法示例。
在下文中一共展示了Request::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
public function __invoke(Request $req, Response $res)
{
$school = $req->getAttribute('school');
$appForm = $this->appFormService->findSchoolApplicationForm($school->id);
if (null === $appForm) {
return $res->withStatus(404);
}
$html = $this->view->fetch('application_form/pdf.twig', ['school' => $school, 'appForm' => $appForm, 'logo' => base64_encode(file_get_contents(__DIR__ . '/../../public/img/application_form/minedu_logo.jpg')), 'style' => file_get_contents(__DIR__ . '/../../public/css/application_form/pdf.css')]);
$pdf = new \Dompdf\Dompdf(['default_paper_size' => 'A4', 'default_font' => 'DejaVu Sans', 'isHtml5ParserEnabled' => true, 'is_remote_enabled' => false]);
$pdf->loadHtml($html);
$pdf->render();
$filename = 'edulabs_app_form_' . $appForm['id'] . '.pdf';
$str = $pdf->output();
$length = mb_strlen($str, '8bit');
return $res->withHeader('Cache-Control', 'private')->withHeader('Content-type', 'application/pdf')->withHeader('Content-Length', $length)->withHeader('Content-Disposition', 'attachment; filename=' . $filename)->withHeader('Accept-Ranges', $length)->write($str);
}
示例2: actionCreate
public function actionCreate(Request $request)
{
if ($request->isXhr()) {
$model = Unit::find($request->getAttribute('id'));
return $this->renderAjax('image/ajax/modal', ['model' => $model]);
}
$this->uploadFiles($request->getUploadedFiles(), $request->getParams(), $request->getAttribute('id'));
return $this->goBack();
}
示例3: __invoke
public function __invoke(Request $req, Response $res)
{
$school = $req->getAttribute('school');
if ($req->isPost()) {
$this->appFormInputFilter->setData(array_merge($req->getParams(), ['school_id' => $school->id, 'submitted_by' => $this->authService->getIdentity()->mail]));
$isValid = $this->appFormInputFilter->isValid();
if ($isValid) {
$data = $this->appFormInputFilter->getValues();
$appForm = $this->appFormService->submit($data);
$_SESSION['applicationForm']['appForm'] = $appForm;
$res = $res->withRedirect($this->successUrl);
return $res;
}
$this->view['form'] = ['is_valid' => $isValid, 'values' => $this->appFormInputFilter->getValues(), 'raw_values' => $this->appFormInputFilter->getRawValues(), 'messages' => $this->appFormInputFilter->getMessages()];
}
$loadForm = (bool) $req->getParam('load', false);
$this->view['choose'] = !$loadForm && !$req->isPost();
if (!$req->isPost() && $loadForm) {
if (null !== ($appForm = $this->appFormService->findSchoolApplicationForm($school->id))) {
$this->view['form'] = ['values' => $appForm];
}
}
$labs = $this->labService->getLabsBySchoolId($school->id);
$res = $this->view->render($res, 'application_form/form.twig', ['lab_choices' => array_map(function ($lab) {
return ['value' => $lab['id'], 'label' => $lab['name']];
}, $labs), 'type_choices' => array_map(function ($category) {
return ['value' => $category['id'], 'label' => $category['name']];
}, $this->assetsService->getAllItemCategories())]);
return $res;
}
示例4: __invoke
public function __invoke(Request $req, Response $res, array $args = [])
{
$school = $req->getAttribute('school', false);
if (!$school) {
return $res->withStatus(403, 'No school');
}
$params = $req->getParams();
$id = $params['id'];
$params['school_id'] = $school->id;
if (isset($params['lessons']) && !is_array($params['lessons'])) {
$params['lessons'] = explode(',', $params['lessons']);
}
unset($params['id']);
try {
if ($id) {
$lab = $this->labservice->updateLab($params, $id);
$res = $res->withStatus(200);
} else {
$lab = $this->labservice->createLab($params);
$res = $res->withStatus(201);
}
$res = $res->withJson($lab);
} catch (Exception $ex) {
$res = $res->withStatus(500, $ex->getMessage());
}
return $res;
}
示例5: __invoke
public function __invoke(Request $req, Response $res)
{
$school = $req->getAttribute('school', false);
if (!$school) {
return $res->withStatus(403, 'No school');
}
$teacherId = $req->getParam('teacher_id');
$teacher = $this->staffService->getTeacherById($teacherId);
if ($teacher['school_id'] !== $school->id) {
return $res->withStatus(403, 'No school');
}
if ($req->isPost()) {
$inputFilter = $this->inputFilter;
$result = $inputFilter($req->getParams());
if (!$result['is_valid']) {
$res = $res->withStatus(422);
$res = $res->withJson($result);
return $res;
}
$this->service->saveAnswers($teacherId, $result['values']);
}
$data = $this->service->getAnswers($teacherId);
$res = $res->withJson($data);
return $res;
}
示例6: getMunicipioDepartamento
function getMunicipioDepartamento(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$id = $request->getAttribute("id");
$data = Municipio::select("municipio.*", "departamento.nombre as departamento")->join('departamento', 'departamento.id', '=', 'municipio.idDepartamento')->where("municipio.id", "=", $id)->first();
$response->getBody()->write($data);
return $response;
}
示例7: borrartipoturnosucursal
function borrartipoturnosucursal(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$data = json_decode($request->getBody(), true);
$id = $request->getAttribute("id");
$tipo = Tipoturnosucursal::select("*")->where("idsucursal", "=", $id)->delete();
$response->getBody()->write($tipo);
return $response;
}
示例8: __invoke
public function __invoke(Request $req, Response $res)
{
$school = $req->getAttribute('school', false);
if (!$school) {
return $res->withStatus(403, 'No school');
}
$this->service->setTotalTeachers($school->id, (int) $req->getParam('total_teachers', 0));
return $res->withStatus(204);
}
示例9: promedio
public function promedio(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$idCliente = $request->getAttribute("idCliente");
$query = "SELECT COALESCE(AVG(calificacion),0) as promedio FROM calificacioncliente WHERE idCliente = " . $idCliente;
$data = DB::select(DB::raw($query));
$response->getBody()->write(json_encode($data));
return $response;
}
示例10: display
/**
* display a static page
*
* @param Request $request
* @param Response $response
* @return Response
*/
public function display(Request $request, Response $response)
{
try {
$res = $this->render($response, sprintf('pages/%s.html', $request->getAttribute('page', 'home')));
} catch (\Exception $e) {
$res = $this->render($response, 'errors/404.html');
}
return $res;
}
示例11: eliminarservicios
function eliminarservicios(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$data = json_decode($request->getBody(), true);
$id = $request->getAttribute("idempleado");
$tipo = ServiciosEmpleado::select("*")->where("idEmpleado", "=", $id)->delete();
$response->getBody()->write($tipo);
return $response;
}
示例12: normalizeProfile
public function normalizeProfile(Request $request, Response $response, callable $next)
{
$routeInfo = $request->getAttribute('routeInfo');
$args = $routeInfo[2];
if (substr($args['username'], -5) == '.json') {
$routeInfo[2]['username'] = substr($args['username'], 0, -5);
$request = $request->withAttribute('routeInfo', $routeInfo)->withHeader('X-Requested-With', 'XMLHttpRequest');
}
return $next($request, $response);
}
示例13: __invoke
public function __invoke(Request $req, Response $res, array $args = [])
{
$school = $req->getAttribute('school', false);
if (!$school) {
return $res->withStatus(403, 'No school');
}
$staff = $this->staffService->getTeachersBySchoolId($school->id);
return $this->view->render($res, 'schools/staff.twig', ['school' => $school, 'staff' => $staff, 'branches' => array_map(function ($branch) {
return ['value' => $branch['id'], 'label' => $branch['name']];
}, $this->staffService->getBranches())]);
}
示例14: get
/**
* display a static page
*
* @param Request $request
* @param Response $response
*/
public function get(Request $request, Response $response)
{
$pdate = str_replace('/', '-', $request->getAttribute('pdate'));
$pslug = $request->getAttribute('pslug');
$pfile = sprintf('%s/blog/%s-%s.md', ROOT_PATH, $pdate, strtolower($pslug));
if (!is_file($pfile) || !is_readable($pfile)) {
return $this->render($response, 'errors/404.html');
}
$f = file_get_contents($pfile);
$t = \Michelf\MarkdownExtra::defaultTransform($f);
return $response->getBody()->write($t);
$pdata = json_decode(file_get_contents($pfile), true);
if (empty($pdata)) {
return $this->render($response, 'errors/500.html');
}
$pdata['published_at'] = $pdate;
$pdata['slug'] = $pslug;
$pdata['url'] = (string) $request->getUri();
return $this->render($response, 'post.html', compact('pdata'));
}
示例15: promocionesByUsuario
function promocionesByUsuario(Request $request, Response $response)
{
$response = $response->withHeader('Content-type', 'application/json');
$id = $request->getAttribute('id');
$data = Promocion::where("idUsuario", "=", $id)->get();
if (count($data) == 0) {
$response = $response->withStatus(404);
}
$response->getBody()->write($data);
return $response;
}