本文整理汇总了PHP中Silex\Application::renderView方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::renderView方法的具体用法?PHP Application::renderView怎么用?PHP Application::renderView使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\Application
的用法示例。
在下文中一共展示了Application::renderView方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Application $app)
{
$app->get('/', function () use($app) {
return $app->renderView('index.html.twig', array('settings' => $app['gearmanui.settings']));
});
$app->get('/status', function () use($app) {
return $app->renderView('status.html.twig');
});
$app->get('/workers', function () use($app) {
return $app->renderView('workers.html.twig');
});
$app->get('/servers', function () use($app) {
return $app->renderView('servers.html.twig');
});
$app->get('/info', function (Request $request) use($app) {
$info = $app['gearman.serverInfo']->getServersInfo();
return new JsonResponse($info);
// return $app->renderView('gearman.json.twig');
});
}
示例2: displayEmailAction
public function displayEmailAction(Application $app, Request $request, $email, $ext)
{
$dns = $this->options['dns'];
$vars = ['login_route' => $request->get('_login_route'), 'register_confirm_route' => $request->get('_register_confirm_route'), 'register_route' => $request->get('_register_route'), 'recover_password_confirm_route' => $request->get('_recover_password_confirm_route'), 'from' => 'no-reply@sup.net', 'to' => 'johndoe@whatever.com'];
switch ($email) {
case 'require_email_verification':
$vars['subject'] = $app['translator']->trans($dns . 'require_email_verification.subject');
$vars['token'] = 'xxxTOKENxxx';
break;
case 'email_verification':
$vars['subject'] = $app['translator']->trans($dns . 'email_verification.subject');
$vars['token'] = 'xxxTOKENxxx';
break;
case 'recover_password':
$vars['subject'] = $app['translator']->trans($dns . 'email_recover_password.subject');
$vars['token'] = 'xxxTOKENxxx';
break;
default:
$app->abort(404, "{$email} not found");
}
$vars = call_user_func($app[$dns . 'twig_vars_injector'], 'email:' . $email, $request, $vars);
return $app->renderView($this->options['ns'] . "/email/{$email}.{$ext}.twig", $vars);
}
示例3: changePasswordAction
public function changePasswordAction(Application $app, Request $request)
{
$dns = $this->options['dns'];
$firewall = $request->get('_firewall');
$changePasswordException = $request->getSession()->get($dns . 'change_password_exception', []);
$changePasswordException += ['field_errors' => [], 'message' => null];
$vars = ['title' => 'User Pack Change Password', 'error' => $changePasswordException['message']];
$userChangePasswordForm = $app->namedForm('user_change_password')->add('old_password', PasswordType::class, ['label' => $dns . 'change_password.labels.old_password'])->add('password', PasswordType::class, ['label' => $dns . 'change_password.labels.password'])->add('confirm_password', PasswordType::class, ['label' => $dns . 'change_password.labels.confirm_password'])->add('submit', SubmitType::class, ['label' => $dns . 'change_password.labels.submit'])->getForm();
$userChangePasswordForm->handleRequest($request);
if ($userChangePasswordForm->isSubmitted()) {
if ($userChangePasswordForm->isValid()) {
$data = $userChangePasswordForm->getData();
/** @var \Symfony\Component\Security\Core\User\User $user */
$user = $app['user'];
$dbUser = $app[$dns . 'user_loader']($user->getUsername(), false);
if (!$app[$dns . 'password_validator']($dbUser->getPassword(), $data['old_password'])) {
$request->getSession()->getFlashBag()->add('message', $app['translator']->trans($dns . 'change_password.messages.bad_old_password'));
$request->getSession()->remove($dns . 'change_password_exception');
return $app->redirect($request->getUri());
}
unset($data['old_password']);
$constraints = [];
$constraints['password'] = new Constraints\Length(['min' => 8, 'minMessage' => $dns . 'change_password.validators.password.length.min', 'max' => 16, 'maxMessage' => $dns . 'change_password.validators.password.length.max']);
$constraints['confirm_password'] = new Constraints\EqualTo(['value' => $data['password'], 'message' => $dns . 'change_password.validators.confirm_password.equal_to.password']);
$constraints = new Constraints\Collection($constraints);
$violations = $app['validator']->validate($data, $constraints);
if (count($violations)) {
$fieldErrors = [];
foreach ($violations as $violation) {
/** @var \Symfony\Component\Validator\ConstraintViolation $violation */
$field = $violation->getPropertyPath();
$field = trim($field, '[]');
if (!isset($fieldErrors[$field])) {
$fieldErrors[$field] = [];
}
$fieldErrors[$field][] = $violation->getMessage();
}
$request->getSession()->set($dns . 'change_password_exception', ['message' => $app['translator']->trans($dns . 'change_password.errors.validation', [], 'errors'), 'field_errors' => $fieldErrors]);
} else {
$dbUser->setPassword($app[$dns . 'password_encoder']($data['password']));
$app['orm.em']->flush();
$request->getSession()->getFlashBag()->add('message', $app['translator']->trans($dns . 'change_password.messages.password_changed'));
$request->getSession()->remove($dns . 'change_password_exception');
}
}
}
if ($request->isMethod('POST')) {
return $app->redirect($request->getUri());
}
foreach ($changePasswordException['field_errors'] as $field => $errors) {
if ($userChangePasswordForm->has($field)) {
foreach ($errors as $error) {
$userChangePasswordForm->get($field)->addError(new FormError($error));
}
}
}
$vars['user_change_password_form'] = $userChangePasswordForm->createView();
foreach ($this->publicRoutes as $route) {
$vars[$route] = $request->get($route);
}
$vars = call_user_func($app[$dns . 'twig_vars_injector'], 'front:' . __METHOD__, $request, $vars);
return $app->renderView($this->options['ns'] . "/front/change_password.html.twig", $vars);
}