Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6023527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:01:07+00:00 2026-05-23T04:01:07+00:00

I use Symfony and Doctrine to generate forms for my CMSes. Lately I’ve been

  • 0

I use Symfony and Doctrine to generate forms for my CMSes. Lately I’ve been customizing them by setting default values based on specific URL parameters.

For example, I have two models: PollQuestion and PollChoice. PollChoice has a relation to PollQuestion by means of a poll_question_id field. The PollChoice form has a dropdown that lists all the available PollQuestions that the PollChoice can be attached to. I also have two routes: pollchoices/new and poll/:poll_id/choice/new. Both routes display the PollChoiceForm, but by using the 2nd route you would automatically see the PollQuestion dropdown set to the :poll_id URL parameter. I do this by simply changing the default value of the dropdown widget in the PollChoiceForm class by fetching the value of :poll_id from the request object.

My question is two-fold:

1) I currently fetch the request object by using sfContext::getInstance()->getRequest(). I know that sfContext::getInstance() is frowned upon, but I haven’t been able to find another way to fetch it. Is there another way? Dependency injection seems like a good way to go, but I don’t know how to accomplish that without doing a lot of hacking (which I’d like to avoid).

2) Am I completely going about the wrong way of changing a form’s default values based on URL parameters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:01:08+00:00Added an answer on May 23, 2026 at 4:01 am

    Whenever I need the context in a form, I’m doing it via constructor injection.

    in the action:

    $this->form = new WhateverForm($whatever, array("context" => $this->getContext()));
    

    in the form:

    $this->getOption("context");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on the project that is based on symfony (doctrine) with use
I just started to use symfony 1.4 and Doctrine. (Used 1.0 - 1.2 +
I use symfony 1.4.15 with doctrine. And I have category and subcategory: Category: actAs:
when i trying to create a module using the command php symfony doctrine:generate-module --with-show
I use symfony's ProjectConfiguration.class.php for configuring doctrine's connection: public function configureDoctrineConnectionCertby(Doctrine_Connection $conn) { $conn->setListener(new
I have been looking at nestedSet behaviour in symfony using doctrine, to display a
I use symfony 1.4.11 with doctrine. I have helper: function filterwords($text){ $filterWords=array ('some','filter','words'); $filterCount
I'm trying to use auto-generated forms in symfony, but I have troubles finding good
I use symfony 1.4.15 with doctrine. I have some static coefficients and I need
i use Symfony 1.4 and Doctrine 1.2. I installed plugin http://www.symfony-project.org/plugins/sfCkPlugin if i add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.