本文整理汇总了PHP中Silex\Application::url方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::url方法的具体用法?PHP Application::url怎么用?PHP Application::url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\Application
的用法示例。
在下文中一共展示了Application::url方法的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: addUserAction
function addUserAction(Request $request, Application $app, $email)
{
/*$user = new \Application\Entity\User();
$form = $this->createForm(new ArticleType(), $article);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($article);
$em->flush();
$session = $this->getRequest()->getSession();
$session->getFlashBag()->add('message', 'Article saved!');
return $this->redirect($this->generateUrl('_form2saved'));
}
//*/
return $app->render('Application/Form/user.twig', ['title' => 'Ajouter un Utilisateur', 'breadcrumb' => [$app->url('application_dashboard') => 'Administration', $app->url('application_administration_users') => 'Utilisateurs', '#' => 'Ajouter']]);
}
示例3: indexAction
public function indexAction(Application $app, Request $req)
{
$form = $app['form.factory']->create(new GuestbookType());
if ($req->getMethod() == 'POST') {
$form->bind($req);
if ($form->isValid()) {
$data = $form->getData();
$app['guestbook']->add($data['name'], $data['message'], $app['request_time'])->save();
return $app->redirect($app->url('homepage'), 303);
}
}
$response = new Response();
$response->headers->set('Surrogate-Control', 'content="ESI/1.0"');
return $app->render('guestbook.twig', ['guestbook' => $form->createView()], $response->setTtl(300));
}
示例4: 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()]);
}
示例5: deleteEntityAction
public function deleteEntityAction($entityName, $entity, Application $app, Request $request)
{
$app['em']->remove($entity);
$app['em']->flush();
return $app->redirect($app->url('cms_list', ['entityName' => $entityName]));
}
示例6: connect
/**
* connect
*
* @param Application $app
*
* @return Silex\ControllerCollection
*/
public function connect(Application $app)
{
// creates a new controller based on the default route
$controllers = $app['controllers_factory'];
$controllers->get('/', function (Application $app) {
return 'It works';
})->bind('msiof-stripe-index');
$controllers->get('/unsubscribe', function (Application $app) {
\Stripe::setApiKey($app['msiof.stripe']['keys']['secret']);
$currentPlan = $app['user']->getCustomField('stripe_current_plan');
if ($currentPlan != $app['msiof.stripe']['plans']['paid']) {
return 'You aren\'t subscribed anyway, so you can\'t unsubscribe';
}
if (empty($app['user']->getCustomField('stripe_customer_id'))) {
return 'You have no stripe customerid, so you can\'t unsubscribe';
}
try {
$customer = \Stripe_Customer::retrieve($app['user']->getCustomField('stripe_customer_id'));
$result = $customer->subscriptions->retrieve($app['user']->getCustomField('stripe_subscription_id_paid'))->cancel(['at_period_end' => true]);
$app['user']->setCustomField('stripe_subscription_awaiting_cancellation', 1);
$app['user.manager']->update($app['user']);
} catch (Exception $e) {
return 'Something went wrong, sorry';
}
$app['session']->getFlashBag()->set('alert-success', 'You are now unsubscribed, but why? :(');
return $app->redirect($app->url('msiof-stripe-account'));
})->bind('msiof-stripe-unsubscribe');
$controllers->get('/account', function (Application $app) {
if (!$app['user']) {
return $app->redirect('user.login');
}
$subscriptionId = $app['user']->getCustomField('stripe_subscription_id_paid');
if (!empty($subscriptionId)) {
if ($app['user']->getCustomField('stripe_subscription_awaiting_cancellation')) {
return 'Your subscription is cancelled';
} else {
return '<a href="/stripe/unsubscribe">Unsubscribe</a>';
}
}
$serverCount = 26;
$form = '
<form action="/stripe/upgrade" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_2bpghGfYvZb4cS2rYIhpcC31"
data-amount="0"
data-name="Upgrade Plan"
data-description="' . $serverCount . ' More Server Fires ($3/server/month)"
data-image="/128x128.png"
data-currency="USD"
data-allowrememberme="false"
data-email="' . $app['user']->getEmail() . '"
data-panelLabel="Subscribe"
data-label="Upgrade"
>
</script>
</form>
';
return $form;
})->bind('msiof-stripe-account');
$controllers->post('/upgrade', function (Application $app, Request $request) {
if (!$app['user']) {
return $app->redirect('user.login');
}
$subscriptionId = $app['user']->getCustomField('stripe_subscription_id_paid');
if (!empty($subscriptionId)) {
$app['session']->getFlashBag()->set('alert', 'You are already subscribed, what ya playing at?');
return $app->redirect($app->url('dashboard'));
}
\Stripe::setApiKey($app['msiof.stripe']['keys']['secret']);
$customerId = $app['user']->getCustomField('stripe_customer_id');
if (empty($customerId)) {
/*
* They don't have a customerid somehow, so we need to make them one
*/
$customer = \Stripe_Customer::create(['email' => $app['user']->getEmail(), 'metadata' => ['userid' => $app['user']->getId()]]);
$subscription = $customer->subscriptions->create(["plan" => $app['msiof.stripe']['plans']['free']]);
$app['user']->setCustomField('stripe_subscription_id_free', $subscription->id);
$app['user']->setCustomField('stripe_customer_id', $customer->id);
$app['user']->setCustomField('stripe_current_plan', $app['msiof.stripe']['plans']['free']);
$app['user.manager']->update($app['user']);
$customerId = $customer->id;
}
$serverCount = 26;
try {
$customer = \Stripe_Customer::retrieve($customerId);
\Stripe_InvoiceItem::create(["customer" => $customerId, "amount" => $serverCount * $app['msiof.stripe']['pricePerServer']['USD'], "currency" => "usd", "description" => "{$serverCount} server fires"]);
$subscription = $customer->subscriptions->create(["plan" => $app['msiof.stripe']['plans']['paid'], "card" => $request->get('stripeToken')]);
$result = $subscription->save();
} catch (Stripe_CardError $e) {
$body = $e->getJsonBody();
$err = $body['error'];
$app['session']->getFlashBag()->set('alert', 'Something was wrong with your card [' . $err['message'] . ']. Please try again.');
//.........这里部分代码省略.........