Hi,
> I am using the sfPropelActAsNestedSetBehaviour and I have to make the
> new element either the root or the child of another node. So I did this
> in my executeEdit() method:
>
> [php]
> public function executeSave()
> {
> $this->store_catalog = $this->getStoreCatalogOrCreate();
>
> if ($this->getRequest()->getMethod() == sfRequest::POST)
> {
> try
> {
> $this->store_catalog->makeRoot();
> $this->store_catalog->save();
> }
> catch (Exception $e)
> {
> ;
> }
> }
>
> return parent::executeSave();
> }
> [/php]
>
>
> But this caused my form to created two new records in the database: one
> was the call of $this->store_catalog->save(); in my executeSave() and
> the other record was created by the call to parent::executeSave(); The
> long story short, the class method getStoreCatalogOrCreate() which is
> auto generated does not account for cases where $this->store_catalog
> already exists and always overwrites it thus creating a new record when
> $this->store_catalog is already a valid StoreCatalog object. I do not
> think I explained very well but this is as good as I can do it :)
>
> This is that needs to be added to $this->getStoreCatalogOrCreate()
>
> [php]
> protected function getStoreCatalogOrCreate($id = 'id')
> {
> if ($this->store_catalog instanceof StoreCatalog) {
> return $this->store_catalog;
> }
> // then the rest of the code it is currently generated
> }
> [/php]
>
> I found a workaround to this problem by adding $_POST['id'] =
> $this->store_catalog->getId(); right after my call to
> $this->store_catalog->save() thus tricking the getStoreCatalogOrCreate()
> method to think that the form is submitted in order to edit the record
> and not to create it but I do not want to use such a workaround when I
> think a permanent solution can be implemented.
It you don't want to actually change the executeEdit() workings but only
do something with the object, why not just overwrite the some of the
other methods?
Like that getStoreCatalogOrCreate(), which would have the benefit, that
you can modify new objects before showing the create form:
protected function getStoreCatalogOrCreate($id = 'id')
{
$storeCatalog = parent::getStoreCatalogOrCreate($id);
if ($storeCatalog->isNew())
{
$storeCatalog->makeRoot(); // or something...
}
else
{
$storeCatalog->doSomethingElse();
}
return $storeCatalog;
}
Or overwrite the saveStoreCatalog() method, which might be simplest in
your case:
protected function saveStoreCatalog($storeCatalog)
{
$storeCatalog->makeRoot(); // or something
parent::save($storeCatalog);
}
Finally, if you really want to customize the executeEdit() method, just
do everything that needs to be done there yourself and don't call the
parent's method at all.
Martin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" 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-devs?hl=en
-~----------~----~----~----~------~----~------~--~---