TYPO3:在扩展控制器中添加自定义设置功能 [英] TYPO3: Add custom set functions in extension controller
问题描述
我正在为访问者创建扩展程序以注册该页面.
注册时,它应该在禁用的后端创建FE用户(并将由管理员手动启用).因此,在创建FE用户时,需要将disable
字段设置为1
.
I'm creating an extension for visitors to sign up to the page.
When signing up, it should create a FE user in the backend which is disabled (and will be manually enabled by an admin). So I'll need to set the disable
field to 1
when creating the FE user.
这是我的控制器内部的功能:
This is the function inside my controller:
/**
* 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)
的东西.
To make this work I'm also loading the $frontendUserRepository
.
I need something like $frontendUser->setDisable(1)
.
环境:TYPO3 7.6.8/PHP 5.6.24/mysqlnd 5.0.11
Environment: TYPO3 7.6.8 / PHP 5.6.24 / mysqlnd 5.0.11
推荐答案
默认情况下,标准用户对象上未启用禁用用户.我已经通过创建从TYPO3扩展FrontendUser的模型并添加了属性禁用功能来解决此问题.
Disabling a user is not default enabled on the standard user object. I've tackled this issue myself by creating a model extending the FrontendUser from TYPO3 and adding a property disable.
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;
}
}
您可能需要一些输入文字才能将其映射到适当的属性
You might need a bit of typoscript to map it to the proper property
config.tx_extbase {
persistence{
classes {
VendorName\ExtensionName\Domain\Model\FrontendUser {
mapping {
tableName = fe_users
columns {
disable.mapOnProperty = disable
}
}
}
}
}
}
您还需要FrontendUserRepository
You'll need the FrontendUserRepository as well
/**
* A Frontend User repository
*/
class FrontendUserRepository extends \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository {
}
此后,您可以将新创建的FrontendUser模型用作FrontendUser的模型,注入它并愉快地使用
After this you can use the newly created FrontendUser model as your model for the FrontendUser, inject it, and happily use
$userModel->setDisable(1);
// and
$userModel->getDisable();
(所有名称空间均已完全编写,这显然没有必要,只是为了易于阅读而已完成)
(All namespaces are fully written, this is not necessary obviously, but simply done for ease of reading)
这篇关于TYPO3:在扩展控制器中添加自定义设置功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!