Never mind, I got it solved. Here's how I did it:
<?php
protected function processForm(sfWebRequest $request, sfForm $form)
{
$formParam = $request->getParameter($form->getName());
if($form->isNew())
{
$formParam['uid'] = $this->getUser()->getId();
}
$form->bind(
$formParam,
$request->getFiles($form->getName())
);
if ($form->isValid())
{
$verhaal = $form->save();
$this->redirect('verhalen', $verhaal);
}
}
> Hello everyone,
>
> I have an table in my database called verhalen. This contains stories
> people wrote. There is an relation between the table stories and the
> table sf_guard_user. (I use sfDoctrineGuardPlugin.)
>
> Now I want to add a new story to the database with a form I created.
> All the columns are filled correctly, exept for the uid (user id)
> field in the verhalen table.
>
> How can I get the user ID from $this->getUser()->getId() and have it
> stored along with the rest of the record? I need the uid field to be
> filled since the query to get the stories from the database depends on
> the value in this field. Below is my code:
>
> <?php
> // actions.class.php
> class verhalenActions extends sfActions
> {
> public function executeNew(sfWebRequest $request)
> {
> $this->form = new VerhalenForm();
> }
> public function executeCreate(sfWebRequest $request)
> {
> $this->form = new VerhalenForm();
> $this->processForm($request, $this->form);
> $this->setTemplate('new');
> }
> protected function processForm(sfWebRequest $request, sfForm $form)
> {
> $form->bind(
> $request->getParameter($form->getName()),
> $request->getFiles($form->getName())
> );
>
> if ($form->isValid())
> {
> $verhaal = $form->save();;
>
> $this->redirect('verhalen', $verhaal);
> }
> }
> }
> ?>
>
> yours,
>
> Bernhard
>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony users" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en
>
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en