On Apr 21, 2:45 am, Adrien Mogenet <adrien.moge...@gmail.com> wrote:
> Symfony 1.2
>
> As I said in my first message, YES, it works when I put `setDefault`
> in the action. But when you call this method from the form class, it
> seems to not FORCE the value but just set it as a default value (ie:
> if no other value has been set)
>
> In my case, it would be very convenient to force this value in the
> action instead of setting it in the form class, that's why I'm looking
> for a "tip" to do that directly from the form class :-)
So you want to force a value from the action? That seems easy enough.
Below I set a default value for the date, but if you took away the if
() statement, instead of a default it would be a forced value.
public function executeUpdate($request)
{
$this->forward404Unless($request->isMethod('post'));
$this->form = new NewNewsForm(NewNewsPeer::retrieveByPk($request-
>getParameter('id')));
$submittedValuesArray = $request->getParameter('new_news');
// 03-12-09 - I'm introducing two categories for now, "front_page"
// and "general". The first is for the weblog, the other is for
any
// other page that might be added to the site.
$category = $request->getParameter('category');
if ($category != "") $submittedValuesArray["category"] =
$category;
/*
* 03-09-09 - if I do this:
* print_r($submittedValuesArray);
* die(" stopped execution ");
*
* I get an array like this:
*
* Array ( [title] => Sagisaws beat the Apaches [description] =>
* A hard fought game, yesterday, down in Del Ray.
* [active] => 1 [id] => )
*
* This is not the correct way to do this, but I'm going to add the
date here.
* If id is not set, in other words, if we are just creating the entry
for the
* first time, then we add a date.
*/
// 03-10-09 - we set the date 24 hours in the future
//
if ($submittedValuesArray["id"] == "") $submittedValuesArray["date"]
= time() + 86400;
$this->form->bind($submittedValuesArray);
if ($this->form->isValid())
{
$new_news = $this->form->save();
$this->redirect('newnews/edit?id='.$new_news->getId());
}
$this->setTemplate('edit');
}
> On 21 avr, 08:11, Lawrence Krubner <lkrub...@geocities.com> wrote:
>
> > Which version of Symfony?
>
> > You should always be able to force a default value from the action.
> > Always. I've done this many times.
>
> > On Apr 20, 5:42 pm, Adrien Mogenet <adrien.moge...@gmail.com> wrote:
>
> > > As I tought it changed nothing... :-/
>
> > > --
> > > Adrien
>
> > > On 20 avr, 23:28, "FlyLM [ML]" <flylm...@gmail.com> wrote:
>
> > > > 2009/4/20 Adrien Mogenet <adrien.moge...@gmail.com>
>
> > > > > Hi all,
>
> > > > > there is something - strange ? - that I don't understand.
> > > > > Let say I have a field "updated_by" within the class "user".
>
> > > > > In the class form :
>
> > > > > public function configure()
> > > > > {
> > > > > ..
> > > > > $this->setDefault('updated_by', '42');
> > > > > ...
> > > > > }
>
> > > > Try this :
>
> > > > $this->widgetSchema->setDefault('updated_by', '42');
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---