I spend a few hours on this so I tought I should share what I did to
be able to set default values for field with the admin generator. May
be it is not the best way. Please, feel free to give your feedback
-------------------------------------------------------------------------------------------------------------------------------------------
I have 2 tables, a status one (it is used to created statuses) and a
site one (it defines site's informations).
When a status is defined, it is linked to a site (site_id is the
field).
When a user connects to the system, his site_id is stored. When
statuses are created, I do want the site_id to be setup to the user's
site_id when the status is saved and I do not want the site_id to
appear in the form.
As Fabien said, fields must be unset in the configure section of
MyappStatusFormClass.php which I did (unset($this['site_id']);).
In my generator.yml file, I had :
form:
display: [site_id, title, corporate]
Until there, everything is fine. I get a form with the title and the
corporate field and when I try to save, I get the error "1 validator
failed on site_id (notnull)" which is normal.
= > So following day 10 of the jobeet tutorial, and under the
action.class.php, I overwrite the executeNew method :
public function executeNew(sfWebRequest $request)
{
$status = new SolveetStatus();
$status->setSiteId(1);
$this->form = new SolveetStatusForm($status);
$this->solveet_status = $this->form->getObject();
}
When I create a status, things are "bizarre". I got the site_id field
drop down list back. I still have my title field, but my corporate
field disappeared.
And If I do the same and remove site_id in the generator.yml file
above, when I save, symfony detect a CSRF attack.
=> Because I did not worked, I tried the other part of the tutorial
(when the token is created) and I overwrite the save method (under lib/
model/doctrine/MyappStatus.class.php) with :
So under myapp\solveet\lib\model\doctrine, I overwrite the save method
under the MyappStatus.class.php with :
public function save(Doctrine_Connection $conn = null)
{
if (!$this->getSiteId())
{
$this->setSiteId(1);
}
return parent::save($con);
}
Of course, here, I set the site_id to 1. But you can replace it by :
$this->getUser()->getAttribute(usersite);
that you previously set when login to your application.
-----------------------------------------------------------------------------------------
Hope it can help others.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---