This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » edit an object with a custom column in admin generator
edit an object with a custom column in admin generator [message #103214] Wed, 28 July 2010 22:27
leonidas79  is currently offline leonidas79
Messages: 5
Registered: May 2010
Location: Morocco
Junior Member
hello everyone

i'm using a nested set to manage a tree ( a User can have an another user as 'parent' ) , so i created a costum column for User object to show 'parent' on the list and it works fine , it's ok also for adding new object ( new User with a parent reference ) , my problem is for editing a User : changing the parent has no effect , i can't see where is the problem.

UserForm.class.php :


class UserForm extends BaseUserForm
{
public function configure()
{
....
$this->setWidget('parent', new sfWidgetFormDoctrineChoice(array('model'=>'User','add_empty'= >true,)));
unset($this['parent_id'],$this['root_id'],$this['lft'],$this ['rgt']);

if($this->getObject()->getNode()->hasParent()){
$this->setDefault('parent', $this->getObject()->getNode()->getParent());
}

public function doSave($con = null){
//save record itself
parent::doSave($con);
//if parent specified ,add/move this node to be the child of that node
if($this->getValue('parent')){
$parent = Doctrine::getTable('User')->findOneBy('id', $this->getValue('parent'));
if($this->isNew()){
$this->getObject()->getNode()->insertAsLastChildOf($parent);
}else{
$this->getObject()->getNode()->moveAsLastChildOf($parent);
}
}
//if no parent was selected , add/move this node to be new root in the tree
else{
$categoryTree = Doctrine::getTable('User')->getTree();
if($this->isNew()){
$categoryTree->createRoot($this->getObject());
}else{
$this->getObject()->getNode()->makeRoot($this->getObject()- >getId());
}
}
}


class User extends BaseUser
{
public function __toString()
{
return sprintf('%s', $this->getNom()." ".$this->getPrenom());
}

public function getParent(){
if($this->getNode()->hasParent()){
$parent = $this->getNode()->getParent();
return $parent;
}
}
}


thx for help
Previous Topic:Issues with propel:build on Propel 1.5
Next Topic:Key-Value Form Design
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software