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 7806795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:38:50+00:00 2026-06-02T02:38:50+00:00

A quick question. I’m using symfony1.4 with Doctrine ORM and sfGuardDoctrinePlugin. I have a

  • 0

A quick question. I’m using symfony1.4 with Doctrine ORM and sfGuardDoctrinePlugin. I have a symfony form named ‘task’. I want the userId field (FK to Id fied if user table) to be set by default to the current logged user. How can I achieve this?

//apps/myapp/modules/task/actions

class taskActions extends sfActions
{
  public function executeNew(sfWebRequest $request)
  {
    $this->form = new taskForm();
  }

  public function executeCreate(sfWebRequest $request)
   {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new taskForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }
}
  • 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-06-02T02:38:52+00:00Added an answer on June 2, 2026 at 2:38 am

    Kind of tricky to answer without seeing how you are setting up the form through the actions, or through the $form->configure(), but you can access the current user id using this:

    $currentUserId = sfContext::getInstance()->getUser()->getGuardUser()->getId();
    

    — Update —

    Based on your update it appears that taskForm is not based off of a model object, otherwise you would be passing an object through the constructor, so it must be a custom form. There are a couple of ways to skin this cat, you can either pass the user object through the constructor or you can set the value through a public accessor, like this:

    class taskForm
    {
        protected $user;
    
        public function setUser($user)
        {
            $this->user = $user;
        }
    
        public function getUser()
        {
            return $this->user;
        }
    
        public function configure()
        {
            // This should output the current user id which demonstrates that you now
            // have access to user attributes in your form class
            var_dump($this->getUser()->getGuardUser()->getId()); 
        }
    }
    

    And to set it:

    public function executeNew(sfWebRequest $request)
    {
        $this->form = new taskForm();
    
        $this->form->setUser($this->getUser());
    }
    

    Another way you may be able to do it is to pass the user object straight through the constructor, then you can reference it using $this->getObject()->getUser() while in form, although I don’t recommend this as it forces the taskForm within a user context.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question... I have a query that checks for duplicates that looks like this:
Quick question. I have an app that use a native DLL through PInvoke, this
Quick question, What have I done wrong here. The purpose of this code is
Quick question about Wordpress PHP: I am writing a theme and I want to
Quick question that requires a long explanation.. Say I have two tables - one
Quick question: I'm using jquery ajax to call a page that returns some json
Quick question about data joining. Say I have some elements that each contain a
Quick question. I have a client with an HTML based website which ranks very,
Quick question, I am using Adobe AIR to develop an app under iPad. Why
Quick question. I have a fortran77 subroutine with a variable declaration DIMENSIONS HH(13, 1000)

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.