本文整理汇总了PHP中Silex\Application::path方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::path方法的具体用法?PHP Application::path怎么用?PHP Application::path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\Application
的用法示例。
在下文中一共展示了Application::path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginRedirectAction
public function loginRedirectAction(Request $request, Application $app)
{
if ($app['security.authorization_checker']->isGranted('ROLE_ADMIN')) {
return $app->redirect($app->path('admin_dashboard'));
}
if ($app['security.authorization_checker']->isGranted('IS_AUTHENTICATED_FULLY')) {
return $app->redirect($app->path('frontend_home'));
}
return $app->redirect($app->path('login'));
}
示例2: indexAction
public function indexAction(Application $app)
{
$files = $app['em']->getRepository('CMSilex\\Entities\\File')->findAll();
$form = $app['form.factory']->createNamedBuilder(null);
$form->add('file', FileType::class)->add('upload', SubmitType::class)->setAction($app->path('upload'));
return $app->render('media/index.html.twig', ['form' => $form->getForm()->createView(), 'files' => $files, 'heading' => 'Media']);
}
示例3: create
public function create(Request $request, Application $app, $id = null)
{
$item = new static::$entity();
$langs = $this->em()->getRepository('\\App\\Entity\\Languages')->findAllActive();
foreach ($langs as $lang) {
if (!$item->hasLang($lang->getId())) {
$newLang = new \App\Entity\ContentLangs();
$newLang->setLanguageId($lang->getId());
$item->addLang($newLang);
}
}
if (!is_null($id)) {
$parent = $this->em()->getRepository(self::$entity)->find($id);
if (is_null($parent)) {
throw new Exception('Item ' . $id . ' not found!');
}
$item->setParent($parent);
}
$form = $app['form.factory']->create(static::$form, $item, array('method' => 'POST', 'action' => $app->path('admin_content_store'), 'attr' => array('role' => 'form'), 'langs' => $langs));
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$item->setParent($form->get('parentId')->getData());
$this->em()->getRepository(self::$entity)->save($item);
$app['session']->getFlashBag()->add('success', 'The item has been created.');
return $app->redirect($app->path($this->cancel_route));
}
}
$this->data['form'] = $form->createView();
$this->data['title'] = 'Add new item';
$this->setTemplate($this->getTemplate() . '_form');
return '';
}
示例4: register
public function register(Request $request, Application $app)
{
if (Auth::user()) {
return $app->redirect($app->path('site.index'));
}
$vars = array();
$form = Form::create('registration_form')->add('name', Type\TextType::class)->add('username', Type\TextType::class, ['constraints' => [new Assert\Regex(['pattern' => '/^[A-Za-z0-9_]+$/', 'match' => true, 'message' => 'Username must only contain alphanumeric characters and underscores.']), new CustomAssert\UniqueRecord(['model' => User::class, 'row' => 'username', 'message' => 'Username already in use.'])]])->add('email', Type\TextType::class, ['constraints' => [new Assert\Email(), new CustomAssert\UniqueRecord(['model' => User::class, 'row' => 'email', 'message' => 'Email already in use.'])]])->add('password', Type\RepeatedType::class, ['type' => Type\PasswordType::class, 'first_options' => ['label' => 'Password'], 'second_options' => ['label' => 'Repeat Password'], 'invalid_message' => 'Password fields did not match.', 'constraints' => [new Assert\Length(['min' => 8, 'minMessage' => 'Password must be at least 8 characters.'])]]);
$form = $form->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
$user = User::create($data);
Auth::login($user);
return $app->redirect($app->path('site.index'));
}
$vars['registration_form'] = $form->createView();
return Theme::view('auth/register', $vars);
}
示例5: tagEdit
public function tagEdit(Application $app, Request $request, $id = null)
{
$title = 'Tag ' . ($id ? 'edit' : 'add');
$data = $id ? $app['tag.model']->find($id) : $app['tag.model'];
$form = $app['form.factory']->createBuilder(new Form\TagType($app), $data)->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$post = $form->getData();
$post->save();
return $app->redirect($app->path('tag'));
}
return $app['twig']->render('admin/form.twig', ['title' => $title, 'form' => $form->createView()]);
}
示例6: connect
/**
* @param Application $app An Application instance
*
* @return ControllerCollection A ControllerCollection instance
*/
public function connect(Application $app)
{
/** @var ControllerCollection $controllers */
$controllers = $app['controllers_factory'];
$controllers->get('/{page}', SearchController::SEARCH)->value('page', 1)->assert('page', '\\d+')->bind('search');
$controllers->get('/manage', function (Application $app) {
return $app->redirect($app->path('manage.members'));
})->bind('manage');
$controllers->get('/manage/members', MemberController::MANAGE)->bind('manage.members');
$controllers->get('/{username}', MemberController::PROFILE)->convert('member', 'converter.member:convert')->bind('profile');
$controllers->match('/manage/members/add', MemberController::ADD)->method('GET|POST')->bind('member.add');
$controllers->post('/member/{username}/delete', MemberController::DELETE)->convert('member', 'converter.member:convert')->bind('member.delete');
return $controllers;
}
开发者ID:hongshuan,项目名称:avid-candidate-challenge-busted,代码行数:19,代码来源:CandidateChallengeControllerProvider.php
示例7: read
public function read(Application $app, $id, $slug)
{
try {
$post = Post::with('author', 'children', 'children.author')->findOrFail($id);
} catch (ModelNotFoundException $e) {
return Theme::view('errors/not_found');
}
if ($slug != $post->slug) {
return $app->redirect($app->path('site.post.read', ['id' => $id, 'slug' => $post->slug]));
}
if (!$post->board->userHasAccess()) {
return Theme::view('errors/access_denied');
}
return Theme::view('post', ['post' => $post->toArray()]);
}
示例8: registerAction
public function registerAction(Request $request, Application $app)
{
$user = new \App\Entity\Users();
$form = $app['form.factory']->create('\\App\\Form\\User\\RegisterType', $user, array('method' => 'POST', 'action' => $app->path('user_register'), 'attr' => array('role' => 'form')));
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
if ($this->isEmailConfirmationRequired) {
$user->setEnabled(false);
$user->setConfirmationToken($app['user.tokenGenerator']->generateToken());
}
try {
$group = $this->em()->getRepository('\\App\\Entity\\Groups')->findOneByName('TESTGROUP');
$user->addGroup($group);
$user->setRoles(array());
$app['user.manager']->save($user);
if ($this->isEmailConfirmationRequired) {
$message = \Swift_Message::newInstance()->setSubject('[' . $app['site_title'] . '] Registration')->setFrom($app['email.site'])->setTo($user->getEmail());
$htmlBody = 'dddddd_html';
$textBody = 'dddddd_text';
$message->setBody($htmlBody, 'text/html')->addPart($textBody, 'text/plain');
$app['mailer']->send($message);
$app['session']->getFlashBag()->add('success', 'Account created.');
return $app->redirect($app['url_generator']->generate('user_confirm'));
} else {
// Log the user in to the new account.
$app['user.manager']->loginAsUser($user);
$app['session']->getFlashBag()->add('success', 'Account created.');
// Redirect to user's new profile page.
//return $app->redirect($app['url_generator']->generate('user_view', array('id' => $user->getId())));
return $app->redirect($app['url_generator']->generate('user_viewself'));
}
} catch (Exception $e) {
$error = $e->getMessage();
$app['session']->getFlashBag()->add('danger', $error);
}
}
}
$this->data['form'] = $form->createView();
self::$page_title = 'Registration';
return '';
}
示例9: contactAction
public function contactAction(Request $request, Application $app)
{
$form = $app['form.factory']->create('\\App\\Form\\Frontend\\FeedbackType', null, array('method' => 'POST', 'action' => $app->path('frontend_contact'), 'attr' => array('role' => 'form')));
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
$data = $form->getData();
$subject = "Message from " . $data['name'];
$msg_body = $app['twig']->render('emails/feedback.twig', $data);
$app['mailer']->send(\Swift_Message::newInstance()->setSubject($subject)->setFrom(array($data['email']))->setTo(array($app['email.feedback']))->setBody($msg_body, 'text/html')->addPart(strip_tags($msg_body), 'text/plain'));
$app['session']->getFlashBag()->add('success', 'Email has been sent.');
return $app->redirect($app['url_generator']->generate('frontend_contact'));
} catch (Exception $e) {
$error = $e->getMessage();
$app['session']->getFlashBag()->add('danger', $error);
}
}
$this->data['form'] = $form->createView();
self::$page_title = 'Contact';
return new Response('', 200, array('Cache-Control' => 's-maxage=3600, public'));
}
示例10: create
public function create(Request $request, Application $app)
{
$user = new static::$entity();
$form = $app['form.factory']->create(static::$form, $user, array('method' => 'POST', 'action' => $app->path('admin_users_store'), 'attr' => array('role' => 'form')));
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
if ($this->isEmailConfirmationRequired) {
$user->setEnabled(false);
$user->setConfirmationToken($app['user.tokenGenerator']->generateToken());
}
$app['user.manager']->save($user);
$app['session']->getFlashBag()->add('success', 'The user ' . $user->getUsername() . ' has been created.');
return $app->redirect($app->path($this->cancel_route));
}
}
$this->data['form'] = $form->createView();
$this->data['title'] = 'Add new user';
$this->setTemplate('form');
return '';
}
示例11: getTaskResourceUrls
private function getTaskResourceUrls(Application $app, $taskId)
{
return ['show' => $app->path('admin_tasks_task_show', ['task' => $taskId]), 'start' => $app->path('admin_tasks_task_start', ['task' => $taskId]), 'stop' => $app->path('admin_tasks_task_stop', ['task' => $taskId]), 'delete' => $app->path('admin_tasks_task_delete', ['task' => $taskId]), 'log' => $app->path('admin_tasks_task_log', ['task' => $taskId])];
}
示例12: connect
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$app['login.controller'] = $this;
$controllers->before(function (Request $request) use($app) {
if ($request->getPathInfo() == $app->path('homepage')) {
return;
}
});
// Displays the homepage
$controllers->get('/', 'login.controller:login')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
if (null !== $request->query->get('postlog')) {
// if isset postlog parameter, set cookie and log out current user
// then post login operation like getting baskets from an invit session
// could be done by Session_handler authentication process
$params = [];
if (null !== ($redirect = $request->query->get('redirect'))) {
$params = ['redirect' => ltrim($redirect, '/')];
}
$response = $app->redirectPath('logout', $params);
$response->headers->setCookie(new Cookie('postlog', 1));
return $response;
}
})->bind('homepage');
// Authentication end point
$controllers->post('/authenticate/', 'login.controller:authenticate')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
})->bind('login_authenticate');
// Guest access end point
$controllers->match('/authenticate/guest/', 'login.controller:authenticateAsGuest')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
})->bind('login_authenticate_as_guest')->method('GET|POST');
// Authenticate with an AuthProvider
$controllers->get('/provider/{providerId}/authenticate/', 'login.controller:authenticateWithProvider')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
})->bind('login_authentication_provider_authenticate');
// AuthProviders callbacks
$controllers->get('/provider/{providerId}/callback/', 'login.controller:authenticationCallback')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
})->bind('login_authentication_provider_callback');
// Logout end point
$logoutController = $controllers->get('/logout/', 'login.controller:logout')->bind('logout');
$app['firewall']->addMandatoryAuthentication($logoutController);
// Registration end point ; redirects to classic registration or AuthProvider registration
$controllers->get('/register/', 'login.controller:displayRegisterForm')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
})->bind('login_register');
// Classic registration end point
$controllers->match('/register-classic/', 'login.controller:doRegistration')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
})->bind('login_register_classic');
// Provide a JSON serialization of registration fields configuration
$controllers->get('/registration-fields/', function (PhraseaApplication $app, Request $request) {
return $app->json($app['registration.fields']);
})->bind('login_registration_fields');
// Unlocks an email address that is currently locked
$controllers->get('/register-confirm/', 'login.controller:registerConfirm')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
})->bind('login_register_confirm');
// Displays a form to send an account unlock email again
$controllers->get('/send-mail-confirm/', 'login.controller:sendConfirmMail')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
})->bind('login_send_mail');
// Forgot password end point
$controllers->match('/forgot-password/', 'login.controller:forgotPassword')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
})->bind('login_forgot_password');
// Renew password end point
$controllers->match('/renew-password/', 'login.controller:renewPassword')->before(function (Request $request) use($app) {
if (null !== ($response = $app['firewall']->requireNotAuthenticated())) {
return $response;
}
})->bind('login_renew_password');
// Displays Terms of use
$controllers->get('/cgus', function (PhraseaApplication $app, Request $request) {
return $app['twig']->render('login/cgus.html.twig', array_merge(['cgus' => \databox_cgu::getHome($app)], self::getDefaultTemplateVariables($app)));
})->bind('login_cgus');
$controllers->get('/language.json', 'login.controller:getLanguage')->bind('login_language');
return $controllers;
//.........这里部分代码省略.........
示例13: recoverPasswordConfirmAction
public function recoverPasswordConfirmAction(Application $app, Request $request, $token)
{
$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 Recover Password', 'error' => $changePasswordException['message']];
try {
$app[$dns . 'token_consumer']('recover_password_confirm', $token, false);
$vars['_user'] = $token->getUser();
$vars['token_type'] = $token->getType();
} catch (TokenException $e) {
switch ($e->getCode()) {
case TokenException::ALREADY_USED:
$vars['error'] = $app['translator']->trans($dns . 'token.errors.already_used', [], 'errors');
break;
case TokenException::TOO_OLD:
$vars['error'] = $app['translator']->trans($dns . 'token.errors.too_old', [], 'errors');
break;
case TokenException::BAD_USE:
$vars['error'] = $app['translator']->trans($dns . 'token.errors.bad_use', [], 'errors');
break;
}
}
$userChangePasswordForm = $app->namedForm('user_change_password')->add('password', PasswordType::class, ['label' => $dns . 'recover_password_confirm.labels.password'])->add('confirm_password', PasswordType::class, ['label' => $dns . 'recover_password_confirm.labels.confirm_password'])->add('submit', SubmitType::class, ['label' => $dns . 'recover_password_confirm.labels.submit'])->getForm();
$userChangePasswordForm->handleRequest($request);
if ($userChangePasswordForm->isSubmitted()) {
if ($userChangePasswordForm->isValid()) {
$data = $userChangePasswordForm->getData();
$constraints = [];
$constraints['password'] = new Constraints\Length(['min' => 8, 'minMessage' => $dns . 'recover_password_confirm.validators.password.length.min', 'max' => 16, 'maxMessage' => $dns . 'recover_password_confirm.validators.password.length.max']);
$constraints['confirm_password'] = new Constraints\EqualTo(['value' => $data['password'], 'message' => $dns . 'recover_password_confirm.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 . 'recover_password_confirm.errors.validation', [], 'errors'), 'field_errors' => $fieldErrors]);
} else {
$app[$dns . 'token_consumer']('recover_password_confirm', $token, true);
$token->getUser()->setPassword($app[$dns . 'password_encoder']($data['password']));
$app['orm.em']->flush();
$request->getSession()->getFlashBag()->add('message', $app['translator']->trans($dns . 'recover_password_confirm.messages.password_changed'));
$request->getSession()->remove($dns . 'change_password_exception');
if ($request->get('_login_route')) {
return $app->redirect($app->path($request->get('_login_route')));
} else {
$app->abort(404);
}
}
}
}
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/recover_password_confirm.html.twig", $vars);
}
示例14: index
public function index(Application $app)
{
return $app->redirect($app->path('site.index'));
}
示例15: groupsCreate
public function groupsCreate(Request $request, Application $app, $id = null)
{
$item = new static::$entity();
$form = $app['form.factory']->create(static::$form, $item, array('method' => 'POST', 'action' => $app->path('admin_groups_store'), 'attr' => array('role' => 'form'), 'controllers' => $this->getAdminControllers()));
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$this->em()->getRepository(self::$entity)->save($item);
$app['session']->getFlashBag()->add('success', 'The item has been created.');
return $app->redirect($app->path($this->cancel_route));
}
}
$this->data['form'] = $form->createView();
$this->data['title'] = 'Add new item';
$this->setTemplate('form');
return '';
}