#php #symfony #doctrine
Вопрос:
У меня есть эта ошибка при отправке формы:
Ожидаемый аргумент типа «BlCoreBundleEntityUsersChannelBrand», «задан экземпляр BlCoreBundleEntityChannelBrand».
UsersType.php
class UsersType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', EmailType::class, array('label' => 'Email'))
->add('username', TextType::class, array('label' => 'Usuario'))
->add('name', TextType::class, array('label' => 'Nombre'))
->add('lastname', TextType::class, array('label' => 'Apellido'))
->add('roles', CollectionType::class, array('label' => 'Roles'))
->add('channelbrand_isolation', CheckboxType::class, array('label' => 'Aislado', 'required' => false))
->add('userschannelbrand', EntityType::class, array(
'class' => 'BlCoreBundleEntityChannelBrand',
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('cb')
->where('cb.isActive =:active')->setParameter('active', true)
->orderBy('cb.name', 'ASC');
},
'choice_label' => 'name',
'multiple' => true,
'label' => 'Canal',
'required' => false,
))
->add('enabled', CheckboxType::class, array('label' => 'Activo', 'required' => false))
;
}
// 'attr' => array(
// 'class' => 'datepicker',
// 'data-provide' => 'datepicker',
// 'data-date-format' => 'yyyy-mm-dd'
// )
// public function getParent()
// {
// return 'FOSUserBundleFormTypeRegistrationFormType';
// }
public function getBlockPrefix()
{
return 'app_user_registration';
}
//
public function getName()
{
return $this->getBlockPrefix();
}
// public function setDefaultOptions(OptionsResolverInterface $resolver) {
// $resolver->setDefaults(array(
// 'data_class' => 'BlCoreBundleEntityUsers',
// 'validation_groups' => array('edit'),
// ));
// }
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'BlCoreBundleEntityUsers',
'validation_groups' => array('edit')
));
}
}
Users.php
class Users extends BaseUser
{
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
$this->addRole("ROLE_USER");
}
/**
* @ORMColumn(name="name", type="string", nullable=true)
*/
protected $name;
/**
* @ORMColumn(name="lastname", type="string",nullable=true)
*/
protected $lastname;
/**
* @ORMColumn(name="channelbrand_isolation", type="boolean")
*/
protected $channelbrandIsolation = false;
/**
* Ids de los channelBrands habilitados para el usuario
* @var array
*/
/**
* Devuelve todos los channelBrands habilitados para el usuario
* @ORMOneToMany(targetEntity="UsersChannelBrand", mappedBy="users", cascade={"persist"})
*/
protected $userschannelbrand;
public function getChb(): array
{
$chb = [];
foreach ($this->getUserschannelbrand()->getIterator() as $res) {
$chb[] = $res->getChannelbrand()->getId();
}
return $chb;
}
public function hasChb(int $id): bool
{
return in_array($id, $this->chb);
}
//
// /**
// *
// * @param int $id
// * @return self
// */
// public function addChb(int $id): self
// {
// if (!$this->hasChb($id)) {
// $this->chb[] = $id;
// }
// return $this;
// }
function getName()
{
return $this->name;
}
function getLastname()
{
return $this->lastname;
}
function setName($name)
{
$this->name = $name;
}
function setLastname($lastname)
{
$this->lastname = $lastname;
}
/**
* Add userschannelbrand.
*
* @param BlCoreBundleEntityUsersChannelBrand $userschannelbrand
*
* @return Users
*/
public function addUserschannelbrand(BlCoreBundleEntityUsersChannelBrand $userschannelbrand)
{
$this->userschannelbrand[] = $userschannelbrand;
return $this;
}
/**
* Remove userschannelbrand.
*
* @param BlCoreBundleEntityUsersChannelBrand $userschannelbrand
*
* @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeUserschannelbrand(BlCoreBundleEntityUsersChannelBrand $userschannelbrand)
{
return $this->userschannelbrand->removeElement($userschannelbrand);
}
/**
* Get userschannelbrand.
*
* @return DoctrineCommonCollectionsCollection
*/
public function getUserschannelbrand()
{
return $this->userschannelbrand;
}
/**
* Set channelbrandIsolation.
*
* @param bool $channelbrandIsolation
*
* @return Users
*/
public function setChannelbrandIsolation($channelbrandIsolation)
{
$this->channelbrandIsolation = $channelbrandIsolation;
return $this;
}
/**
* Get channelbrandIsolation.
*
* @return bool
*/
public function getChannelbrandIsolation()
{
return $this->channelbrandIsolation;
}
}
Я вызываю UsersChannelBrand на UsersType.php потому что у этой организации есть список активных брендов.. но у меня есть эта ошибка при отправке, как я могу ее исправить?
С уважением!
Комментарии:
1. класс’ => ‘BlCoreBundleEntityChannelBrand’, может быть подсказкой.
2. Да, я ввожу ChannelBrand, но User.php не узнаю его … у меня есть все каналы, но я не могу управлять им, ахах
3. Вы даете ему имя пользователя. Не бренд канала. Отсюда и сообщение об ошибке.
4. Да, но мне нужно получить все идентификаторы channelbrand.. я не понимаю, как я могу передать идентификаторы channelbrand User.php :/