本文整理汇总了PHP中Silex\Application::form方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::form方法的具体用法?PHP Application::form怎么用?PHP Application::form使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\Application
的用法示例。
在下文中一共展示了Application::form方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect
public function connect(Application $app)
{
$controller = $app['controllers_factory'];
$controller->get('/', function (Application $app, Request $request) {
return $app['twig']->render('admin/dashboard.html.twig');
})->bind('dashboard');
$controller->match('/settings', function (Application $app, Request $request) {
$qb = $app['em']->createQueryBuilder();
$qb->select('s')->from('CMSilex\\Entities\\Setting', 's', 's.att');
$currentSettings = $qb->getQuery()->getResult();
$builder = $app->form($currentSettings);
$form = $builder->add('about', TextareaType::class)->add('github', TextType::class)->add('Save', SubmitType::class)->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$allSettings = $form->getData();
foreach ($allSettings as $key => $value) {
$newSetting = new Setting($key, $value);
$app['em']->merge($newSetting);
}
$app['em']->flush();
return $app->redirect($app->url("settings"));
}
return $app['twig']->render('admin/settings.html.twig', ['form' => $form->createView()]);
})->bind('settings')->method('POST|GET');
return $controller;
}
示例2: resetPassword
public function resetPassword(Application $app, Request $request)
{
$form = $app->form(new PhraseaRenewPasswordForm());
if ('POST' === $request->getMethod()) {
$form->bind($request);
if ($form->isValid()) {
$data = $form->getData();
$user = $app['authentication']->getUser();
if ($app['auth.password-encoder']->isPasswordValid($user->getPassword(), $data['oldPassword'], $user->getNonce())) {
$app['manipulator.user']->setPassword($user, $data['password']);
$app->addFlash('success', $app->trans('login::notification: Mise a jour du mot de passe avec succes'));
return $app->redirectPath('account');
} else {
$app->addFlash('error', $app->trans('Invalid password provided'));
}
}
}
return $app['twig']->render('account/change-password.html.twig', array_merge(Login::getDefaultTemplateVariables($app), ['form' => $form->createView()]));
}
示例3: registerAction
public function registerAction(Application $app, Request $request)
{
$builder = $app->form();
$builder->add('email', EmailType::class)->add('password', RepeatedType::class, ['type' => PasswordType::class, 'first_options' => ['label' => 'Password'], 'second_options' => ['label' => 'Repeat Password']])->add('register', SubmitType::class);
$form = $builder->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$userInfo = $form->getData();
$newUser = new User();
$password = $app->encodePassword($newUser, $userInfo['password']);
$newUser->setUsername($userInfo['email']);
$newUser->setPassword($password);
$newUser->setEnabled(true);
$newUser->setAccountNonExpired(true);
$newUser->setAccountNonLocked(true);
$newUser->setCredentialsNonExpired(true);
$newUser->setRoles(['ROLE_USER']);
$app['em']->persist($newUser);
$app['em']->flush();
return $app->redirect($app->url('login'));
}
return $app->render('authentication/register.html.twig', ['form' => $form->createView()]);
}
示例4: postSaveTask
public function postSaveTask(Application $app, Request $request, Task $task)
{
if (!$this->doValidateXML($request->request->get('settings'))) {
return $app->json(['success' => false, 'message' => sprintf('Unable to load XML %s', $request->request->get('xml'))]);
}
$form = $app->form(new TaskForm());
$form->setData($task);
$form->bind($request);
if ($form->isValid()) {
$app['manipulator.task']->update($task);
return $app->json(['success' => true]);
}
return $app->json(['success' => false, 'message' => implode("\n", $form->getErrors())]);
}
示例5: form
/**
* @see \Silex\Application\FormTrait::form
*/
public function form($data = null, array $options = [], $type = null)
{
return $this->app->form($data, $options, $type);
}
示例6: postSaveTask
public function postSaveTask(Application $app, Request $request, Task $task)
{
if (false === $app['phraseanet.configuration']['main']['task-manager']['enabled']) {
throw new RuntimeException('The use of the task manager is disabled on this instance.');
}
if (!$this->doValidateXML($request->request->get('settings'))) {
return $app->json(['success' => false, 'message' => sprintf('Unable to load XML %s', $request->request->get('xml'))]);
}
$form = $app->form(new TaskForm());
$form->setData($task);
$form->bind($request);
if ($form->isValid()) {
$app['manipulator.task']->update($task);
return $app->json(['success' => true]);
}
return $app->json(['success' => false, 'message' => implode("\n", $form->getErrors())]);
}