-
Notifications
You must be signed in to change notification settings - Fork 161
Using BjyAuthorize with Doctrine 2 and FormMultiCheckbox #117
Comments
@lampi87 this does not look like a BjyAuthorize issue. It's more about how you're managing your entities. You should use DoctrineModule's form elements and show some code first. |
The entities are more or less the same which are provided with bjyauthorize. The problems started with updating my vendor directory. Person entity (main part): public function getRoles()
{
return $this->roles->getValues();
}
public function addRoles(Collection $roles)
{
foreach ($roles as $role) {
$role->getPersons()->add($this);
$this->roles->add($role);
}
}
public function removeRoles(Collection $roles)
{
foreach ($roles as $role) {
$role->getPersons()->removeElement($this);
$this->roles->removeElement($role);
}
} Role entity: class Role implements HierarchicalRoleInterface
{
/**
* @var int
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(type="string", length=255, unique=true, nullable=true)
*/
protected $roleId;
/**
* @var Role
* @ORM\ManyToOne(targetEntity="Vrcts\Entity\Role")
*/
private $parent;
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = (int)$id;
}
public function getRoleId()
{
return $this->roleId;
}
public function setRoleId($roleId)
{
$this->roleId = (string) $roleId;
}
public function getParent()
{
return $this->parent;
}
public function setParent(Role $parent)
{
$this->parent = $parent;
}
} PersonForm: $this->add(
array(
'type' => 'DoctrineORMModule\Form\Element\EntityMultiCheckbox',
'name' => 'roles',
'options' => array(
'object_manager' => $this->getObjectManager(),
'target_class' => 'Base\Entity\Role',
'property' => 'roleId'
)
)
); The wrong role is selected (this should be a bjyauthorized issue) selected. User (parent of admin) is selected instead of admin. |
Maybe there is a problem at the point where the role collection is built up or is returned |
I have no idea of what is going on here, but this is not BjyAuthorize issue. Ask on the mailing list first (zf mailing list) or on stackoverflow. Also not sure where things happen since you didn't provide a stack trace. As said, ask on the ML/StackOverflow first. |
The stack trace after saving the form ( ! ) Fatal error: Call to a member function toArray() on a non-object in /home/alex/git/base/vendor/doctrine/doctrine-module/src/DoctrineModule/Stdlib/Hydrator/Strategy/AllowRemoveByValue.php on line 56 Time Memory Function Location1 0.0001 257816 {main}( ) ../index.php:0 |
Yep, as you see this is only happening in the abstract hydrator. You should really ask on the mailing list first. There's no single BjyAuthorize in that stack trace. |
I know, that there is not single BjyAuthorize in that stack trace, but this happens till I have updated my entities to fit to the new version. one main change is that my getRole function
now returns only the values and not the collection as it was done before the main change of handling Doctrine entities. If I switch back to return the whole collection byjauthorize errors occur |
That's because the Marco Pivetta On 11 March 2013 14:11, Alex Lampret [email protected] wrote:
|
@lampi87 were you able to fix this issue? I've run into the same problem. |
I have created a second function (i.e. getUserRoles) which returns the arraycollection
and I'm using this function for my forms |
Maybe this issue about managing roles with ZfcUserAdmin is interesting: |
Hi!
I started to rewrite site with new bjyauthorize version cloned today. The navigation works. But using FormMultiCheckbox does not work.
If have two roles, user & admin. User is the parent role of admin. So every admin can access all users sites and more. My current user has the role admin. On my PersonForm the wrong option, user, is selected. And I got the php notice "Object of class Base\Entity\Role could not be converted to int in vendor/zendframework/zendframework/library/Zend/Form/View/Helper/FormMultiCheckbox.php on line 293"
Save is not possible too (Call to a member function toArray() on a non-object in vendor/doctrine/doctrine-module/src/DoctrineModule/Stdlib/Hydrator/Strategy/AllowRemoveByValue.php on line 57)
Please, can you help me?
Greetings
The text was updated successfully, but these errors were encountered: