我正在为访问者创建一个扩展程序,以便注册该页面
注册时,它应该在后端创建一个FE用户,该用户被禁用(并且将由管理员手动启用)。因此,在创建FE用户时,我需要将disable
字段设置为1
。
这是我的控制器内部的功能:
/**
* action create
*
* @param \Vendor\FeReg\Domain\Model\Dummy $newDummy
* @return void
*/
public function createAction(\Vendor\FeReg\Domain\Model\Dummy $newDummy)
{
// vars
$title = $newDummy->getTitle();
$atitle = $newDummy->getAtitle();
$fname = $newDummy->getFname();
$lname = $newDummy->getLname();
$street = $newDummy->getStreet();
$city = $newDummy->getCity();
$post = $newDummy->getPost();
$phone = $newDummy->getPhone();
$fax = $newDummy->getFax();
$email = $newDummy->getEmail();
$org = $newDummy->getOrg();
$cat = $newDummy->getCat();
$field = $newDummy->getField();
$uname = $newDummy->getUname();
$ppass = $newDummy->getPpass();
$cpass = $newDummy->getCpass();
$fulltitle = ($atitle ? $title." ".$atitle : $title);
$frontendUser = new FrontendUser();
$frontendUser->setUsername($uname);
$frontendUser->setPassword($ppass);
$frontendUser->setFirstname($fname);
$frontendUser->setLastname($lname);
$frontendUser->setAddress($street);
$frontendUser->setTelephone($phone);
$frontendUser->setFax($fax);
$frontendUser->setEmail($email);
$frontendUser->setTitle($fulltitle);
$frontendUser->setZip($post);
$frontendUser->setCity($city);
$frontendUser->setCompany($org);
$this->frontendUserRepository->add($frontendUser);
// $this->dummyRepository->add($newDummy);
// $this->addFlashMessage($title, '', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
$this->redirect('new');
}
为了完成这项工作,我还要加载$frontendUserRepository
我需要像$frontendUser->setDisable(1)
这样的东西。
环境:TYPO3 7.6.8 / PHP 5.6.24 / mysqlnd 5.0.11
答案 0 :(得分:5)
在标准用户对象上未启用禁用用户的默认设置。我自己通过创建一个从TYPO3扩展FrontendUser并添加属性禁用的模型来解决这个问题。
class FrontendUser extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
/**
* @var boolean
*/
protected $disable;
/**
* Gets the Disable
*
* @return boolean
*/
public function getDisable() {
return (bool)$this->disable;
}
/**
* Sets the Disable
*
* @param boolean $disable
* @return void
*/
public function setDisable($disable) {
$this->disable = (bool)$disable;
}
}
您可能需要一些typoscript将其映射到适当的属性
config.tx_extbase {
persistence{
classes {
VendorName\ExtensionName\Domain\Model\FrontendUser {
mapping {
tableName = fe_users
columns {
disable.mapOnProperty = disable
}
}
}
}
}
}
您还需要FrontendUserRepository
/**
* A Frontend User repository
*/
class FrontendUserRepository extends \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository {
}
在此之后,您可以使用新创建的FrontendUser模型作为FrontendUser的模型,注入它,并愉快地使用
$userModel->setDisable(1);
// and
$userModel->getDisable();
(所有名称空间都是完整的,显然不是必需的,但只是为了便于阅读而完成)